What is a Jquery
- Jquery is a fast,small and rich javascript library which allows us to make Html document traversal and manipulation,event handling,animation and ajax.
- It works across a cross browsers.
How to make sure that DOM is ready using Jquery
- By using $(document).ready() function we can make sure that DOM is ready.
How javascript and jquery are different
- Javascript is a scripting language which Jquery is a library built in the javascript language that helps us to use Javascript language.
Can we have multiple document.ready() function on the same page
- Yes we can have any number of document.ready() function on the same page.
What is a Jquery selector
- Jquery selector is a function which makes use of expression to find out the matching element from a DOM based on the given criteria.
- We can simply say that jquery selectors are used to select one or more html elements using jquery.Once an element is selected then we can perform various operations on a selected element.
How to select elements using jquery with the given tag name
- $('tagname') will select all the element of type tag name in the document.
- For example $('p') selects all the paragraphs <p> in the document.
How to select single element using jquery with given element id
- $('id1') will select the single element in the document that has an ID of 'id1'.
How to select elements using Jquery whose css class is cssclass1
- $('.cssclass1') selects all the elements in the document that has a class of cssclass1.
How to select all elements using Jquery
- $('*') selects all elements available in the document.
How to select multiple elements using Jquery
- $('h1,div,span') will selects the specified selectors using jquery.
How to get attributes of an element using Jquery
- The attr() method can be used to fetch the value of an attribute from the first element in the matched set.
- Example:$("img").attr("width","500");
How to remove an attribute from each of matched elements using Jquery
- The removeAttr(name) can be used to remove an attribute from each of matched elements.
What is difference between .each() and $.each()
- .each() is used to iterate over only jquery object collections where as $.each() allows us to iterate over javascript objects and arrays.
What is the fastest selectors in Jquery
- ID and elements are fastest selectors in Jquery.
What is the slowest selectors in jquery
- CSS selectors are the slowest selectors in jquery.
What is Jquery.noConflict
- We have other client side libraries like MooTool,Prototype can be used with jquery and they also use $() as their global function and to define variables.Hence it creates a conflict as $() is used by Jquery and other libraries as a global function.To overcome this we make use of jquery.noConflict()
What is difference between body onload() and document.ready function
- We can have more than one document.ready function in a page where as we can have only one body onload function.
- document.ready function is called as soon as DOM is loaded where as body onload function is called when everything gets loaded on the page that includes DOM,images and all resources of the page.
What is difference between Size and length of Jquery
- Both size and length returns the number of elements in an object.But length is faster than size as length is a property and size is a method.
What is difference between attr and prop
- jquery.attr() gets the value of an attribute for the first element in the set of matched elements.
- jquery.prop() gets the value of a property for the first element in the set of matched elements.
When to use $(window).load instead of $(document).ready
- In most cases script can be executed as soon as DOM is fully loaded so ready() function is the best place to write the javascript code.
- But in some cases we need to make use of load() function to write script.For example to get the actual width and height of an image we make use of load() function.
- As we know that load() function gets fired once DOM and all the css,images are fully loaded.So load() function is the best place to get width and height of an image.