jQuery Articles

Found 413 articles

What is $(window).load() method in jQuery?

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

The code which gets included inside $( window ).on( "load", function() { ... }) runs only once the entire page is ready (not only DOM).Note: The load() method deprecated in jQuery version 1.8. It was completely removed in version 3.0. To see its working, add jQuery version for CDN before 3.0.ExampleYou can try to run the following code to learn how to use $(window).load() method in jQuery − $(document).ready(function(){    $("img").load(function(){      alert("Image successfully loaded.");    }); }); Note: The load() method deprecated in jQuery version 1.8. It was completely removed in version 3.0. To see its working, add jQuery version for CDN before 3.0.

Read More

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

Kristi Castro
Kristi Castro
Updated on 11-Mar-2026 859 Views

To change background color, use the mouseenter event. The background color change when you place mouse cursor:mouseenter: function(){    $(this).css("background-color", "gray"); }The mouse cursor is placed on the following element:Click and move the mouse pointer to change the background color.You can try to run the following code to learn how to animate a change in background color on mouseover:Example               $(document).ready(function(){          $("body").on({             mouseenter: function(){                $(this).css("background-color", "gray");             },                 mouseleave: function(){                $(this).css("background-color", "red");             },              });       });        Click and move the mouse pointer to change the background color.

Read More

How to center a div on the screen using jQuery?

Kristi Castro
Kristi Castro
Updated on 11-Mar-2026 763 Views

To center a div on the screen, use the jQuery centering function jQuery.fn.center. You can try to run the following code to learn how to center a div on the screen:Example               $(document).ready(function(){       jQuery.fn.center = function(parent) {         if (parent) {           parent = this.parent();         } else {           parent = window;         }       this.css({        "position": "absolute",        "top": ((($(parent).height() - ...

Read More

How to clear HTML form fields with jQuery?

usharani
usharani
Updated on 11-Mar-2026 2K+ Views

With jQuery, you can easily clear HTML form fields. For this, jQuery: reset Selector is used. This will clear the HTML form fields.ExampleYou can try to run the following code to clear form fields with jQuery −                          $(document).ready(function(){             $(":reset").css("background-color", "#F98700");          });                              Student Name          Student Subject                              

Read More

Align the components with Bootstrap

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 11-Mar-2026 386 Views

To align the components like nav links, forms, buttons, or text to left or right in a navbar using the utility classes .navbar-left or .navbar-right. Both classes will add a CSS float in the specified direction.ExampleYou can try to run the following code to align components           Bootstrap Example                                                       Alignment                                                                                                    Java                                                                                jmeter                      EJB                      Jasper Report                                            Separated link                                            One more separated link                                                                          Left align-Submit Button                         Left align-Text                                                                                Java                                                                                jmeter                      EJB                      Jasper Report                                            Separated link                                            One more separated link                                                                                             Right align-Submit Button                                         Right align-Text                    

Read More

How to exclude first and second element from jQuery selector?

Amit D
Amit D
Updated on 11-Mar-2026 991 Views

To exclude first and second element from jQuery, use the slice() method.ExampleYou can try to run the following code to exclude first and element from jQuery: $(document).ready(function(){    $('p').slice(2).css('font-size', '24px'); }); Java C++ Ruby Groovy

Read More

How to check which key has been pressed using jQuery?

Amit D
Amit D
Updated on 11-Mar-2026 851 Views

To check which key has been pressed, use the onkeydown attribute.ExampleYou can try to run the following code to get which key is pressed: Press a key in the below box to get which key is pressed.   function demoFunction(event) {     var a = event.key;     document.getElementById("test").innerHTML = "You've pressed the key: " + a;   }

Read More

How to disable right click using jQuery?

Alex Onsman
Alex Onsman
Updated on 11-Mar-2026 3K+ Views

To disable right click on a page, use the jQuery bind() method.ExampleYou can try to run the following code to learn how to disable right click: $(document).ready(function(){    $(document).bind("contextmenu",function(e){       return false;    }); }); Right click is disabled on this page.

Read More

How to get the input value of the first matched element using jQuery?

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

To get the input value of the first matched element using jQuery, use the .first() method.ExampleYou can try to run the following code to get the input value of the first matched element using jQuery −                          $(document).ready(function(){            $( "li" ).first().css( "background-color", "blue" );          });                              One          Two          Three          Four          

Read More

What is the difference between switchClass() and toggleClass() methods in jQuery?

Amit D
Amit D
Updated on 11-Mar-2026 490 Views

The switchClass() is used to switch class from an element. Use it, to replace one class with another. Add jQuery UI library to the web page to use switchClass().ExampleYou can try to run the following code to learn how to work with switch class −                          $(document).ready(function(){           $("a").click(function(){              $("a.active").removeClass("active");              $(this).addClass("active");            });          });               ...

Read More
Showing 1–10 of 413 articles
« Prev 1 2 3 4 5 42 Next »
Advertisements