jQuery Articles

Page 15 of 42

How to get attribute of an element when using the 'click' event in jQuery?

Ricky Barnes
Ricky Barnes
Updated on 13-Mar-2026 3K+ Views

To get attribute of an element, use the attr() method in jQuery. The attr() method retrieves the value of an attribute from the first element in the matched set of elements. When used with click events, it allows you to dynamically access element attributes when user interactions occur. Example You can try to run the following code to get attribute of an element using the 'click' event − $(document).ready(function(){ $("button").click(function(){ ...

Read More

How to check the element type of an event target with jQuery?

Ricky Barnes
Ricky Barnes
Updated on 13-Mar-2026 2K+ Views

To check the element type of an event target, we use the is() method. The is() method checks the current matched set of elements against a selector and returns true if at least one of these elements matches the given arguments. Example You can try to run the following code to check the element type − $(document).ready(function(){ $("ul").click(function(event) { ...

Read More

How to handle a mouse right click event using jQuery?

David Meador
David Meador
Updated on 13-Mar-2026 4K+ Views

To handle a mouse right click event, use the mousedown() jQuery method. Mouse left, right and middle click can also be captured using the same method. The event.which property helps identify which mouse button was clicked: 1 for left, 2 for middle, and 3 for right mouse button. Example You can try to run the following code to learn how to handle a mouse right click event − $(document).ready(function(){ ...

Read More

How to handle a double click event using jQuery?

David Meador
David Meador
Updated on 13-Mar-2026 1K+ Views

To handle a double click event using jQuery, use the dblclick() event. When an element is double clicked, this event occurs. The dblclick() method triggers the double-click event or attaches a function to run when a double-click event occurs on the selected elements. Syntax The basic syntax for the dblclick() method is − $(selector).dblclick(function) Where function is optional and specifies the function to run when the double-click event occurs. Example You can try to run the following code to learn how to handle double click event using jQuery − ...

Read More

How to handle a link click event using jQuery?

David Meador
David Meador
Updated on 13-Mar-2026 5K+ Views

To handle a click event using jQuery, use the click() method. This method allows you to attach a function that executes when a user clicks on a link or any other element. You can try to run the following code to handle a link click event using jQuery − Example Here's a complete example that demonstrates handling link click events − $(document).ready(function(){ $("a").click(function(){ ...

Read More

How can I remove everything inside of a using jQuery?

David Meador
David Meador
Updated on 13-Mar-2026 719 Views

To remove everything inside a div element, you can use jQuery's empty() method or remove() method. The empty() method removes all child elements while keeping the div itself, whereas remove() removes the entire div element including its contents. Using empty() Method The empty() method is the most appropriate choice when you want to clear the contents inside a div while preserving the div element itself − $(document).ready(function(){ ...

Read More

How can I remove all elements except the first one using jQuery?

Amit D
Amit D
Updated on 13-Mar-2026 2K+ Views

To remove all elements except the first one, use the remove() method with the slice() method in jQuery. The slice(1) method selects all elements starting from index 1 (the second element), leaving the first element untouched. Example You can try to run the following code to remove all elements except for first one using jQuery − $(document).ready(function(){ $(".button1").click(function(){ ...

Read More

How to duplicate a div using jQuery?

David Meador
David Meador
Updated on 13-Mar-2026 3K+ Views

To duplicate a div in jQuery, use the jQuery clone() method. The clone() method creates a deep copy of the selected element, including all its child elements and attributes. Syntax The basic syntax of the clone() method is − $(selector).clone(includeEvents) Where includeEvents is an optional boolean parameter that specifies whether to copy event handlers along with the element. By default, it is false. Example You can try to run the following code to learn how to duplicate a div using jQuery − ...

Read More

How to change CSS using jQuery?

David Meador
David Meador
Updated on 13-Mar-2026 773 Views

To change CSS using jQuery, use the jQuery css() method. This method allows you to modify CSS properties of selected elements dynamically. Syntax The css() method can be used in two ways − Single property: $(selector).css("property", "value") Multiple properties: $(selector).css({"property1": "value1", "property2": "value2"}) Example You can try to run the following code to change CSS using jQuery − $(document).ready(function(){ // Single property change - changes ...

Read More

How to find left position of element in horizontal scroll container using jQuery?

David Meador
David Meador
Updated on 13-Mar-2026 2K+ Views

To find the left position of element in horizontal scroll container using jQuery, use the offset() function combined with scrollLeft(). The offset() method returns the coordinates of an element relative to the document, while scrollLeft() gets or sets the horizontal scroll position. The key is to calculate the left offset by subtracting the container's left offset from the element's left offset, then adding the current scroll position of the container. Example You can try to run the following code to learn how to find left position of an element in horizontal scroll container − ...

Read More
Showing 141–150 of 413 articles
« Prev 1 13 14 15 16 17 42 Next »
Advertisements