Add active class onclick javascript and jQuery

Add active class to a div on javascript onclick event Here we are applying a style to a simple div. Steps to add a css class on click event

Add active class onclick javascript to HTML ul List to make menu Here We have ul list elements to create horizontal menu on click on … Read more

Jquery toggle an element

toggle is a method which is used to show and hide the selected class. if select element is hidden then on toggle it will show element.If element is not hidden on toggle it will hide the element. Photography Photography is the science, art and practice of creating durable images by recording light or other electromagnetic … Read more

jquery get parent id based on class value

If we have nested divs one inside another and we want to get id of parent div for this we use parents(). suppose following div structure

as above we have seen how to get id for top parent and similar we can get id or class value for any level of parent. for … Read more

Struts2 Json and Jquery Example

Here we will fetch a action variable’s value in jsp page using JSON and jquery Here I am using struts 2.3.4 for that we have to include struts-2-json-plugin-2.3.4.jar in class path or include it to your lib folder if you are using any IDE. Action class

In struts.xml we have to extend json-default and … Read more

How to get multiple checkbox value in javascript and JQuery

On many websites, you find multiple check box forms to select your interest, or to select multiple options. That can be created by using the HTML check box.

Here to make an input as a text box we need type=”checkbox”. name is a name given to a text box value property that specifies what … Read more

Getting id and class value of a html element

We have a div and we want to get its id value based on its class value. Suppose a div is given as below and we want to fetch div id based on a button click. for getting attribute id we use attr() method. Example


Replacing content of div using .replaceWith()

To replace the content of a div span or any other block elements content with html element a jquery method .replaceWith() is used. Syntax:


A selector can be id class or tag selector of element to replace with newContent passed in .replaceWith() method. a newContent can be html string, DOM element, Array … Read more

Jquery html method

html() is used to get or set the html content in matched selector. Getting content using html() Html() get contents with html tags of specified selector If more then one elements are there with same selector then only first matched elements content are get using html(). for setting html content we pass string argument in … Read more

Showing JQuery Arraylist values using Struts2 and JSON

I am having comment class, I want to show its property values to jsp page using json

ListJson assigning values for Here we fetch value of commentList and totalcomments value in our jsp page.


In Jsp page

Hide and show html elements using jquery

Hide and show function are used to show and hide any html element. Here on button click we are showing and hiding the div.

Output We can also provide how long this hide or show will take place be specifying the time like $(“.description”).hide(2000); or $(“.description”).show(2000); to perform specific task after hide or … Read more