Found 766 Articles for JQuery

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

David Meador
Updated on 12-Dec-2019 08:29:42

329 Views

jQuery.size() methodThis method returns the number of elements in the object. The size() method deprecated in jQuery 1.8 and completely removed in jQuery 3.0. As an alternative, the length property is used.ExampleYou 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 deprecated in jQuery 1.8. Generally, the length property is preferred now.Live Demo $(document).ready(function(){     $(".btn").click(function(){         alert($("li").size());     }); }); How many li elements? ... Read More

What is the difference between jQuery and JavaScript?

Kiran Kumar Panigrahi
Updated on 28-Jul-2022 16:07:56

2K+ Views

Both JavaScript and jQuery serve the same overarching objective of making the webpages more interactive and dynamic. They give the websites a sense of vibrancy. People may ask why there is a need for two distinct ideas if they serve the same function and are utilised in the same way. Read through this article to find out how jQuery differs from JavaScript.What is JavaScript?JavaScript is a lightweight programming language that is used most often as a component of webpages. Its webpage implementations enable client-side script to interact with the user and create dynamic sites. It is a programming language that ... Read More

How to add display:none in an HTML element using jQuery?

David Meador
Updated on 17-Feb-2020 10:05:49

3K+ Views

To workaround with display: none in an element in jQuery, use the hide() method. It will do the same work.ExampleYou can try to run the following code to learn how to add display:none in an HTML element −Live Demo $(document).ready(function(){   $("button").click(function(){     $("p").removeAttr("style").hide();   }); }); Heading 1 This is demo text. This will hide on button click. This is another text. This will hide on button click Hide

How to toggle a div visibility using jQuery?

David Meador
Updated on 17-Feb-2020 10:04:26

7K+ Views

To toggle a div visibility in jQuery, use the toggle() method. It checks the div element for visibility i.e. the show() method if div is hidden. And hide() id the div element is visible. This eventually creates a toggle effect.The toggle( speed, [callback]) method toggles displaying each of the set of matched elements using a graceful animation and firing an optional callback after completion.Here is the description of all the parameters used by this method −speed − A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).callback − ... Read More

What are the options for jQuery Animated Effects?

David Meador
Updated on 12-Dec-2019 07:53:30

105 Views

jQuery animated effected can be achieved with methods such as animate, slideDown(), slideToggle(), etc. This created an animation effect in an HTML web page using jQuery. The following table lists down some of the important methods to create different kind of effects:S. NoMethods & Description1.animate( params, [duration, easing, callback] )A function for making custom animations.2.fadeIn( speed, [callback] )Fade in all matched elements by adjusting their opacity and firing an optional callback after completion.3.fadeOut( speed, [callback] )Fade out all matched elements by adjusting their opacity to 0, then setting display to "none" and firing an optional callback after completion.4.fadeTo( speed, opacity, ... Read More

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

David Meador
Updated on 15-Jun-2020 11:02:16

18K+ 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.ExampleLive Demo $(document).ready(function(){     $('#show').click(function() {       $('.menu').toggle("slide");     }); }); Click to Show/ Hide div             India       US       UK       Australia      

How can I show and hide an HTML element using jQuery?

David Meador
Updated on 15-Jun-2020 10:57:41

1K+ Views

To hide and show an HTML element using jQuery, use the hide and show() methods. Here, the element is hidden and shown on button click,ExampleLive Demo $(document).ready(function(){     $("#visible").click(function(){         $("p").show();     });      $("#hidden").click(function(){         $("p").hide();     }); }); This text  will show on clicking "Show element" button, and hide on clicking "Hide element" button. Hide element Show element

What is the difference between error () and ajaxError() events in jQuery?

David Meador
Updated on 17-Feb-2020 09:56:32

187 Views

jQuery error() methodThe error() method triggers the event when an element encounters an error. This method deprecated in jQuery 1.8.ExampleYou can try to run the following code to learn how to work with error() method in jQuery −Live Demo $(document).ready(function(){     $("img").error(function(){         $("img").replaceWith("Image isn't loading");     });     $("button").click(function(){         $("img").error();     }); }); Error event jQuery ajaxError() methodThe ajaxError( callback ) method attaches a function to be executed whenever an AJAX request fails. This is an ... Read More

How to include multiple js files using jQuery $.getScript() method?

David Meador
Updated on 17-Feb-2020 09:54:08

533 Views

To use multiple js files, use the same getScript(), which is used to add a single js file. We’re having result.js file with the following code snippet −function CheckJS(){    alert("This is JavaScript - File1"); }We’re having result2.js file with the following code snippet −function CheckJS(){    alert("This is JavaScript – File2"); }ExampleHere's the code snippet to add multiple js files. Here, we will call the function in the above 2 js files −                                 $(document).ready(function() {             ... Read More

How to detect eventType in jQuery?

David Meador
Updated on 17-Feb-2020 09:48:11

128 Views

To detect the eventType in jQuery, use the event type property. You can try to run the following code to learn how to detect eventType in jQuery −ExampleLive Demo  $(document).ready(function(){     $("p").on("mouseover mouseout",function(event){         $("div").html("Event Type: " + event.type);     });  }); This has mouseover and mouseout event defined. Keep your cursor to see the event type below.

Advertisements