jQuery Articles

Page 9 of 42

How to create wrapper div around two other divs with jQuery?

Amit D
Amit D
Updated on 13-Mar-2026 653 Views

To create wrapper div around two other divs, use the wrapAll() method. The wrapAll() method wraps a single HTML structure around all matched elements in the set. This is particularly useful when you want to group multiple elements together within a common container. Syntax The basic syntax of the wrapAll() method is − $(selector).wrapAll(wrappingElement) Where wrappingElement can be an HTML string, DOM element, or jQuery object that will serve as the wrapper. Example You can try to run the following code to create wrapper div around two other divs with jQuery − ...

Read More

How to add easing effect to your animation with jQuery?

Ricky Barnes
Ricky Barnes
Updated on 13-Mar-2026 675 Views

To add easing effects to your jQuery animations, you need to use the animation speed properly and choose the right easing function to create perfect animations for your web page. The key is knowing when to speed up, slow down, and stop your animations while using the animate() method. jQuery provides several built-in easing options like "swing" and "linear", or you can use custom easing functions for more advanced effects. The "swing" easing creates animations that start slow, speed up, then slow down at the end, while "linear" maintains a constant speed throughout the animation. The key is to control ...

Read More

How to disable/enable an input box with jQuery?

Arnab Chakraborty
Arnab Chakraborty
Updated on 13-Mar-2026 18K+ Views

We can easily disable input boxes (textbox, textarea) using the disabled attribute. When an input element is disabled, users cannot interact with it, and it won't be included in form submissions. Using attr() and removeAttr() Methods To disable an input element − $('elementname').attr('disabled', 'disabled'); To enable a disabled element, we need to remove the "disabled" attribute from the element − $('elementname').removeAttr('disabled'); Using prop() Method (Recommended) jQuery also provides the prop() method which is recommended for boolean attributes like disabled − // To disable $('elementname').prop('disabled', true); // ...

Read More

How to disable/ enable checkbox with jQuery?

Kristi Castro
Kristi Castro
Updated on 13-Mar-2026 7K+ Views

To disable and enable checkboxes, use the attr() method or prop() method in jQuery. The disabled attribute prevents users from interacting with the checkbox, making it unclickable and visually grayed out. Using the attr() Method Initially set the input type checkbox and disable it − Male Now on the click of a button, toggle between disabled and enabled checkbox − $("#button1").click(function() { $("#sName").attr('disabled', !$("#sName").attr('disabled')); }); Example The following example demonstrates how to toggle checkbox state using the attr() approach rewritten in vanilla JavaScript (since jQuery CDN is not available in the ...

Read More

How to make a textarea and input type read only using jQuery?

Kristi Castro
Kristi Castro
Updated on 13-Mar-2026 3K+ Views

To make a textarea and input type read only, use the attr() method or the prop() method in jQuery. The readonly attribute prevents users from editing the content while still allowing the elements to be focused and their values to be submitted with the form. Using the attr() Method The attr() method sets HTML attributes on selected elements. To make input fields and textareas read only, set the readonly attribute − $('input[type="text"], textarea').each(function() { $(this).attr('readonly', 'readonly'); }); Example The following example uses the attr() method to set readonly on a text input and textarea ...

Read More

How can I show and hide div on mouse click using jQuery?

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

To show and hide div on mouse click using jQuery, use the toggle() method. On mouse click, the div is visible and on again clicking the div, it hides. The toggle() method is a convenient jQuery function that automatically switches between showing and hiding elements. When an element is visible, toggle() will hide it, and when it's hidden, toggle() will show it. Example Here's a complete example that demonstrates how to show and hide a div on mouse click − ...

Read More

How can I make jQuery animations smoother?

Kristi Castro
Kristi Castro
Updated on 13-Mar-2026 707 Views

To make jQuery animations smoother, use the easing library and set appropriate animation speeds to create perfect animations for your web page. Avoid speeding up animations excessively and know when to stop them while using animate(). The easing library provides various transition effects like swing, linear, easeIn, and easeOut that make animations appear more natural and polished. Key Tips for Smoother Animations Here are essential techniques to improve jQuery animation quality − Use proper timing: Choose appropriate duration values (fast, slow, or milliseconds) Chain animations: Link multiple ...

Read More

How to animate a change in background color using jQuery on mouseover?

Kristi Castro
Kristi Castro
Updated on 13-Mar-2026 892 Views

To change background color with animation, use the mouseenter and mouseleave events. The background color changes smoothly when you place the mouse cursor over an element using jQuery's animate() method. For basic color change without animation, you can use the css() method − mouseenter: function(){ $(this).css("background-color", "gray"); } However, to create smooth animated transitions, jQuery's animate() method provides better visual effects. The mouse cursor interaction is applied to the following element − Move the mouse pointer to animate the background color change. Example You can try ...

Read More

How animate(), hide and show elements using jQuery?

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

jQuery provides powerful methods to animate, hide and show elements with smooth visual effects. You can use the animate() method combined with hide() and show() methods to create dynamic animations that enhance user experience. animate() Method The animate() method allows you to create custom animations by gradually changing CSS properties. When combined with hide() and show() methods as callback functions, you can create smooth transition effects. Syntax $(selector).animate({properties}, speed, callback); Example Here's a complete example showing how to animate elements before hiding and showing them − ...

Read More

What is the difference between jQuery.size() and jQuery.length?

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

jQuery.size() method returns the number of elements in the jQuery object. The size() method was deprecated in jQuery 1.8 and completely removed in jQuery 3.0. As an alternative, the length property is used. Example You can try to run the following code to learn how to work with size() method − Note: To run the jQuery size() method, use jQuery version less than 1.8, since it was deprecated in jQuery 1.8. Generally, the length property is preferred now. ...

Read More
Showing 81–90 of 413 articles
« Prev 1 7 8 9 10 11 42 Next »
Advertisements