Found 766 Articles for JQuery

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

David Meador
Updated on 14-Feb-2020 04:57:45

4K+ 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 −Live Demo $(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.

What is $(document).ready() method in jQuery?

David Meador
Updated on 13-Sep-2023 03:59:52

25K+ Views

The ready() method is used to make a function available after the document is loaded. Whatever code you write inside the $(document ).ready() method will run once the page DOM is ready to execute JavaScript code.ExampleYou can try to run the following code to learn how to use $(document).ready() method in jQuery:Live Demo           jQuery Function                     $(document).ready(function() {           $("div").click(function() {             alert("Hello, world!");           });         });                                  Click on this to see a dialogue box.          

How should I initialize jQuery in a web page?

David Meador
Updated on 14-Feb-2020 04:56:43

1K+ Views

To initialize jQuery in a web easy is quite easy. You can try to run the following code to learn how to initialize jQuery in a web page. We’re using Google CDN to add jQuery. Microsoft CDN is also available for the same purpose of adding jQuery library to HTML.ExampleLive Demo           jQuery Function                      $(document).ready(function() {             $("div").click(function() {alert("Welcome to Tutorialspoint!");});          });                                  Click on this to see a dialogue box.          

How to add and remove HTML attributes with jQuery?

Alex Onsman
Updated on 14-Feb-2020 04:55:22

512 Views

To add and remove HTML attributes with jQuery, use the addClass() and removeClass() method.You can try to run the following code to add and remove HTML attributes with jQuery −ExampleLive Demo           jQuery Example                      $(document).ready(function(){                      $( '#add' ).click( function () {                $('#page_navigation1').addClass( 'blue-class' );                    });                      $( '#remove' ).click( function () {                        $('#page_navigation1').removeClass( 'blue-class' );                    });              });                                  .blue-class {            background-color: blue;            font-size: 30px;          }              Demo    Add    Remove

How to remove all the attributes of an HTML element using jQuery?

Alex Onsman
Updated on 13-Feb-2020 11:28:58

962 Views

To remove all the attributes of an HTML element, the removeAttr() method won’t work. For this, create an array and use removeAllAttrs() to remove all the attributes of a specific HTML element. For example, remove the image by removing the attributes of the img element.You can try to run the following code to learn how to remove all the attributes from an element. We’re removing the img element attribute −ExampleLive Demo           Selector Example                      $(document).ready(function() {             $(".remove-attr").click(function(){     ... Read More

How to remove all style attributes using jQuery?

Alex Onsman
Updated on 13-Feb-2020 11:19:08

7K+ Views

To remove an attribute from each tag using jQuery, use the removeAttr() method and use the Universal Selector. Let us see how to use the method to remove all style attribute. Use the universal selector also to select all the elements.You can try to run the following code to learn how to remove all style attributes using jQuery −ExampleLive Demo $(document).ready(function(){   $("button").click(function(){     $("h1").removeAttr("style");   }); }); This is heading This is demo text. This is heading This is demo text. Remove Click above to remove style attribute from all h1 elements.

How to remove an attribute from each tag using jQuery?

Alex Onsman
Updated on 13-Feb-2020 11:04:42

244 Views

To remove an attribute from each tag using jQuery, use the removeAttr() method. You can try to run the following code to learn how to remove attribute −ExampleLive Demo $(document).ready(function(){   $("button").click(function(){     $("h1").removeAttr("style");   }); }); This is heading This is demo text. This is heading This is demo text. Remove Click above to remove style attribute from all h1 elements.

What are the methods in jQuery to manipulate attributes?

Alex Onsman
Updated on 13-Jun-2020 06:41:35

74 Views

jQuery comes with a lot of methods to manipulate attributes. These are DOM related methods. The attributes include,text() – This method sets or returns the text content of elements selected.html() – This method sets or returns the content of elements selected.val() – This method sets or returns the value of form fields.You can try to run the following code to learn how to manipulate attributes with text() and html() methods −Example $(document).ready(function(){    $("#button1").click(function(){      alert("Using text- " + $("#demo").text());    });    $("#button2").click(function(){      alert("Using html()- " + $("#demo").html());    }); }); This is demo text. Text HTML

What are the methods used to provide effects in jQuery?

David Meador
Updated on 12-Jun-2020 13:09:08

739 Views

jQuery effect methods are used to create custom animation effects. The following are some of the methods used to provide effects in jQuery −S.NoMethodDescription1animate()Custom animation on the selected elements2clearQueue()To remove remaining queued functions from the selected elements3delay()To set a delay for all queued functions on the selected elements4dequeue()To remove the next function from the queue, and then executes the function5fadeIn()Fades in the selected elements6fadeOut()Fades out the selected elements7fadeTo()Fades in/out the selected elements to a given opacity8fadeToggle()To Toggle between the fadeIn() and fadeOut() methods9finish()To stop, remove and complete all queued animations for the selected elementsLet’s see an example to work with ... Read More

How to add a class on click of anchor tag using jQuery?

David Meador
Updated on 13-Feb-2020 09:56:22

1K+ Views

To add a class on click of anchor tag using jQuery, use the addClass() method. You can try to run the following code to learn how to implement adding a class on click of anchor tag using jQuery −ExampleLive Demo                       $(document).ready(function() {         $("a").click(function() {           $("a.active").removeClass("active");           $(this).addClass("active");         });       });                   .active {          font-size: 22px;         }                     One       Two       Click any of the link above and you can see the changes.    

Advertisements