81⟩ How to reduce the set of matched elements to a single element using jQuery?
The eq( index ) method reduces the set of matched elements to a single element.
“JQuery Programmer Frequently Asked Questions in various JQuery Developer job Interviews by interviewer. The set of questions here ensures that you offer a perfect answer posed to you. So get preparation for your new job hunting”
The eq( index ) method reduces the set of matched elements to a single element.
jQuery javascript can be downloaded from jQuery official website - www.jquery.com
Dollar ($) sign is used as a shortcut for jQuery.
Following example shows how the variable counter is visible within the create, increment, and print functions, but not outside of them −
function create() {
var counter = 0;
return {
increment: function() {
counter++;
},
print: function() {
console.log(counter);
}
}
}
var c = create();
c.increment();
c.print(); // ==> 1
Use $(document).ready() function. Everything inside it will load as soon as the DOM is loaded and before the page contents are loaded.
jQuery code is getting executed on a client browser.
The removeAttr( name ) method can be used to remove an attribute from each of the matched elements.
jQuery is a Javascript file and it is single javascript file that contains common DOM, event effects and Ajax functions.
$('.some-class') selects all elements in the document that have a class of some-class.
slideToggle() effect is used to give animated sliding effect to an element.
Syntax:
slideToggle([ duration] [, easing] [, callback])
1. "duration" is the number specifying how long the animation will run.
2. "easing" is the string which specify the function for the transition.
3. "callback" is the function which we want to run once the animation is complete.
4. If the element is visible then this effect will slide the element up side and make it completely hidden. If the element is hidden then slideToggle() effect will slide it down side and make it visible.
5. We can specify the toggle speed with this effect.
For example
$("#clickme").click(function()
{
$("#mydiv").slideToggle("slow", function()
{
//run after the animation is complete.
});
});
Yes, we can call C# code from jQuery as it supports .net application.
jQuery is a library of JavaScript file and it consists of DOM, event effects and the Ajax functions. jQuery is said to be a single JavaScript file.
YES. We can have any number of document.ready() function on the same page.
The height( val ) method sets the CSS height of every matched element.
In a page, we can have only one onload function but we can have more than one document.ready function. Document.ready function is called when DOM is loaded but onload function is called when DOM and images are loaded on the page.
► To deal with cookies in jQuery we have to use the Dough cookie plugin.
► Dough is easy to use and having powerful features.
1. Create cookie
$.dough("cookie_name", "cookie_value");
2. Read Cookie
$.dough("cookie_name");
3. Delete cookie
$.dough("cookie_name", "remove");
Yes.
As other client side libraries like MooTools, Prototype can be used with jQuery and they also use $() as their global function and to define variables. This situation creates conflict as $() is used by jQuery and other library as their global function. To overcome from such situations, jQuery has introduced jQuery.noConflict().
jQuery.noConflict();
// Use jQuery via jQuery(...)
jQuery(document).ready(function(){
jQuery("div").hide();
});
You can also use your own specific character in the place of $ sign in jQuery.
var $j = jQuery.noConflict();
// Use jQuery via jQuery(...)
$j(document).ready(function(){
$j("div").hide();
});
The is( selector ) method checks the current selection against an expression and returns true, if at least one element of the selection fits the given selector.
$('*') selects all elements available in a DOM.