InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 101. |
What Are The Fastest Selectors In Jquery? |
|
Answer» ID and ELEMENT SELECTORS are the FASTEST selectors ID and element selectors are the fastest selectors |
|
| 102. |
Jquery Uses Css Selectors And Xpath Expressions To Select Elements True Or False? |
|
Answer» True True |
|
| 103. |
What $("div.tutoriz") Will Select? |
|
Answer» All the DIV ELEMENT with tutoriz CLASS. All the div element with tutoriz class. |
|
| 104. |
Write A Basic Code For Add Jquery Library To Pages? |
|
Answer» Answer :
<html>
<head> |
|
| 105. |
What Scripting Language Is Jquery Written In? |
|
Answer» JavaScript JavaScript |
|
| 106. |
When J Query Founded And By Whom? |
|
Answer» It was RELEASED in JANUARY 2006 at BarCamp NYC by John Resig(JQUERY FOUNDER). It was released in January 2006 at BarCamp NYC by John Resig(Jquery founder). |
|
| 107. |
What Is The Struts2 Jquery Plugin And Its Advantages? |
|
Answer» The struts2 jquery plugin is used to:
For example: <div id="result">Result Div</div> The advantages of USING it are:
The struts2 jquery plugin is used to: For example: <div id="result">Result Div</div> The advantages of using it are:
|
|
| 108. |
Explain The Use Of The $.fn.bind And $.fn.trigger? |
|
Answer» Both the $.fn.bind and $.fn.triggers are two important jquery METHODS. They are primarily used with CUSTOM events.
Example: depicting the usage of $.fn.bind and $.fn.triggers using custom data in both the cases: $(DOCUMENT).bind('myCustomEvent',{foo:'bar'}, function(e, arg1, ARG2) { console.log(e.data.foo); // 'bar' console.log(arg1); // 'bim' console.log(arg2); // 'baz' }); $(document).trigger('myCustomEvent',['bim','baz']);Both the $.fn.bind and $.fn.triggers are two important jquery methods. They are primarily used with custom events. Example: depicting the usage of $.fn.bind and $.fn.triggers using custom data in both the cases: |
|
| 109. |
Write The Code To Define A Requirejs Module With Its Dependencies? |
|
Answer» The RequireJS is a DEPENDENCY management tool that can be used by the USER to manage script modules. It can be used to load scripts once a PAGE has been loaded. This helps in EVENLY distributing the DOWNLOADS. For example: RequireJS module with dependencies defined: require.def("my/shirt",["my/cart", "my/inventory"], function(cart, inventory) { //return an object to define the "my/shirt" module. return { color: "blue", size: "large" addToCart: function() { inventory.decrement(this); cart.add(this); } } } ); In the above example the my.shirt module is created. This module depends on the my/cart and my/inventory. The RequireJS is a dependency management tool that can be used by the user to manage script modules. It can be used to load scripts once a page has been loaded. This helps in evenly distributing the downloads. For example: RequireJS module with dependencies defined: In the above example the my.shirt module is created. This module depends on the my/cart and my/inventory. |
|
| 110. |
Write A Code For The Implementation Of A Module Pattern? |
|
Answer» The OBJECT literal does not provide any privacy for the methods or properties. The module PATTERN allows the user to offer privacy to functions and variables. It can be USED to SET to expose limited API. For example: The module pattern code: var FEATURE =(function() { var privateThing = 'secret', publicThing = 'not secret', changePrivateThing = function() { privateThing = 'super secret'; }, sayPrivateThing = function() { console.log(privateThing); changePrivateThing(); }; return { publicThing : publicThing, sayPrivateThing : sayPrivateThing } })(); feature.publicThing; // 'not secret' feature.sayPrivateThing();The object literal does not provide any privacy for the methods or properties. The module pattern allows the user to offer privacy to functions and variables. It can be used to set to expose limited API. For example: The module pattern code: |
|
| 111. |
How Can Related Code Be Encapsulated? Give Example? |
|
Answer» The object literal is one of the SIMPLEST ways that the user can encapsulate related code together. It helps by removing any anonymous FUNCTIONS from the USERS code. It can also be used to CENTRALIZE CONFIGURATION options. For example: An object literal being implemented var myFeature={ myProperty : 'hello', myMethod : function() { console.log(myFeature.myProperty); }, init : function(settings) { m2yFeature.settings = settings; }, readSettings : function() { console.log(myFeature.settings); } }; myFeature.myProperty; // 'hello' myFeature.myMethod(); // logs 'hello' myFeature.init({ foo : 'bar' }); myFeature.readSettings(); // logs { foo :'bar' }The object literal is one of the simplest ways that the user can encapsulate related code together. It helps by removing any anonymous functions from the users code. It can also be used to centralize configuration options. For example: |
|
| 112. |
Explain Some Of The Key Concepts Of Good Code Organization Patterns? |
|
Answer» Some of the KEY concepts that should be followed while
Some of the key concepts that should be followed while |
|
| 113. |
How Is The Deferred Method In Jquery Important In Relation To Animate Method? |
|
Answer» The .animate() method is used to CREATE animations with other shorthands using it. The queue() method can be used to link TOGETHER multiple animation METHODS to create an unique effect. These methods are effective when all the data is available locally and all the methods are executed on as single system only. In case the user wants to use the animation methods on a data that resides on the server and wants to handle at a single go the user can make used of the .deferred method. For example: var my$ = $.sub(); my$.fn.animate=function(props,SPEED,easing,callback){var options=speed && typeof speed==="object"? jQuery.extend({}, speed) : { complete: callback || !callback && easing || jQuery.isFunction( speed ) && speed, duration: speed, easing: callback && easing || easing && !jQuery.isFunction(easing) && easing }; var dfd = my$.Deferred(), complete = options.complete, count = this.length; options.complete = function() { complete && complete.call( this ); if ( !--count ) { dfd.resolve(); } }; The .animate() method is used to create animations with other shorthands using it. The queue() method can be used to link together multiple animation methods to create an unique effect. These methods are effective when all the data is available locally and all the methods are executed on as single system only. In case the user wants to use the animation methods on a data that resides on the server and wants to handle at a single go the user can make used of the .deferred method. For example: |
|
| 114. |
Explain The Use Of The .pushstack() Method? |
|
Answer» The pushStack() method works by ACCEPTING an array of DOM elements and pushes them into a stack. This is done so that call to methods like .end() and .andSelf are able to behave correctly. The jquery internally uses this method to keep TRACK of all the previous COLLECTIONS of jquery while using a chain traversing method. Good examples of such methods COULD be .parents() and .filter(). For example: // select some divs The pushStack() method works by accepting an array of DOM elements and pushes them into a stack. This is done so that call to methods like .end() and .andSelf are able to behave correctly. The jquery internally uses this method to keep track of all the previous collections of jquery while using a chain traversing method. Good examples of such methods could be .parents() and .filter(). For example: // select some divs |
|
| 115. |
Create A Plugin That Would Add And Remove A Class On Hover? |
|
Answer» The plugin can be considered to be simply a new method that can be used by a user to extend the prototype object of a jquery. A plugin performs some ACTIONS on a COLLECTION of elements. Each method that comes with the jquery core can be considered to be a plugin. The code for CREATING a plugin that would add and remove a CLASS on hover would be as follows: (function($){ $.fn.hoverClass = function(c) { return this.hover( function() { $(this).toggleClass(c); } ); }; })(jQuery); // using the plugin $('li').hoverClass('hover');The plugin can be considered to be simply a new method that can be used by a user to extend the prototype object of a jquery. A plugin performs some actions on a collection of elements. Each method that comes with the jquery core can be considered to be a plugin. The code for creating a plugin that would add and remove a class on hover would be as follows: |
|
| 116. |
Explain The Common Methods Of Sending A Request To A Server? |
|
Answer» The two most common methods of sending a request to a server are :
GET method: The get method is mostly used for non destructive operations. These operations get data from the server and does not change the data on it. A good example of the application of the SEARCH query to a server. In most of the cases GET will send all of the data to be sent in the form of a query string. POST method: The POST method is primarily used for destructive operations. These operations can change the data on a server. A good example is a user saving an entry on a SITE will get the POST request. These requests are not CACHED by the browser. A query can be a part of a url but any data that is to be sent is done separately as post data. The two most common methods of sending a request to a server are : GET method: The get method is mostly used for non destructive operations. These operations get data from the server and does not change the data on it. A good example of the application of the search query to a server. In most of the cases GET will send all of the data to be sent in the form of a query string. POST method: The POST method is primarily used for destructive operations. These operations can change the data on a server. A good example is a user saving an entry on a site will get the POST request. These requests are not cached by the browser. A query can be a part of a url but any data that is to be sent is done separately as post data. |
|
| 117. |
How Does Jquery Store Data Related To An Element? |
|
Answer» In plain java scripts the information about an element can be stored by adding a domain object model property to the element. This results in memory leak PROBLEMS in certain BROWSERS. In jquery the user does not has to worry about memory management issues. For example: storing and retrieving data related to an element: $('#myDiv').data('keyName', { foo : 'bar' }); $('#myDiv').data('keyName'); // { foo : 'bar' }Jquery allows the user to STORE any kind of information on an element. The $.fn.data is used the most to store data related to an element. For ex. storing of relationship between ELEMENTS with the use of $.fn.data : $('#myList li').each(function() { var $li = $(this), $div = $li.find('div.content'); $li.data('contentDiv', $div); }); // LATER, the user is not required to look for the div again; // the data can simply be read from the list items data; var $firstLi = $('#myList li:first'); $firstLi.data('contentDiv').html('new content');In plain java scripts the information about an element can be stored by adding a domain object model property to the element. This results in memory leak problems in certain browsers. In jquery the user does not has to worry about memory management issues. For example: storing and retrieving data related to an element: Jquery allows the user to store any kind of information on an element. The $.fn.data is used the most to store data related to an element. For ex. storing of relationship between elements with the use of $.fn.data : |
|
| 118. |
What Are The Approaches Of Extracting A Query String With Regular Expressions? |
|
Answer» There are two approaches of doing so: String based approach: This is the simple way of extracting the information of a query string using the string-based replacement technique. This method makes use of the .replace() method to function. For example: var data = string.replace("http://localhost/view.php?", ""); The above code works fine for the string based approach but has some flexibility ISSUES. It cannot deal effectively with DOMAIN name and file name changes. Regular expression approach: They are a powerful pattern matching tool available in modern PROGRAMMING LANGUAGES. For the extraction of a query string a pattern would have to be used which LOOKS for a question mark in the string. Once it does it returns everything after it. The regular expression in JS are delimited using the forward slashes at the end of an expression. There are two approaches of doing so: String based approach: This is the simple way of extracting the information of a query string using the string-based replacement technique. This method makes use of the .replace() method to function. For example: var data = string.replace("http://localhost/view.php?", ""); The above code works fine for the string based approach but has some flexibility issues. It cannot deal effectively with domain name and file name changes. Regular expression approach: They are a powerful pattern matching tool available in modern programming languages. For the extraction of a query string a pattern would have to be used which looks for a question mark in the string. Once it does it returns everything after it. The regular expression in JS are delimited using the forward slashes at the end of an expression. |
|
| 119. |
Why Is The Block Display Style Used For Animations? |
|
Answer» In html only the block LEVEL elements can have custom HEIGHTS and widths. So when a user defines an animation method for usage such as show, hide, slide up etc the display css property of the block being animated is set to display block style. On completion of the animation the display style of the block would be CHANGED to its original value. This procedure does not work properly for inline elements and the following workarounds can be applied to it:
In html only the block level elements can have custom heights and widths. So when a user defines an animation method for usage such as show, hide, slide up etc the display css property of the block being animated is set to display block style. On completion of the animation the display style of the block would be changed to its original value. This procedure does not work properly for inline elements and the following workarounds can be applied to it: |
|
| 120. |
How Can An Element Be Checked If It Contains A Specific Class? |
|
Answer» The hasClass method DEFINED can be used to check if an ELEMENT actually contains the specified class. For example: usage of the hasClass: $("div").click(function(){if ( $(this).hasClass("PROTECTED") ) $(this) .animate({ left: -10 }) .animate({ left: 10 }) .animate({ left: -10 }) .animate({ left: 10 }) .animate({ left: 0 }); }); The is() method can also be used with a SELECTOR for a more advanced level of matching. For example: if ( $('#myDiv').is('.pretty.awesome') ) $('#myDiv').show();This method can be used to test various other things, such as it could be used to detect if the specified element is hidden or not. The hasClass method defined can be used to check if an element actually contains the specified class. For example: usage of the hasClass: The is() method can also be used with a selector for a more advanced level of matching. For example: This method can be used to test various other things, such as it could be used to detect if the specified element is hidden or not. |
|
| 121. |
How Can Events Be Prevented From Stopping To Work After An Ajax Request? |
|
Answer» There are two ways to handle this ISSUE: Use of event delegation: The event delegation technique works on principle by exploiting the event bubbling. It uses event bubbling to capture the events on elements which are present anywhere in the domain object model. In jquery the user can make use of the live and die methods for the events delegation which contains a subset of event types. For example: handling event delegation, handling of CLICKS on any element: $('#mydiv').click(function(e){ if( $(e.target).is('a') )fn.call(e.target,e); }); $('#mydiv').load('my.html') Event rebinding usage: When this method is USED it requires the user to call the BIND method and the added NEW elements. For example: $('a').click(fn); $('#mydiv').load('my.html' ,function(){$('#mydiv a').click(fn); }); There are two ways to handle this issue: Use of event delegation: The event delegation technique works on principle by exploiting the event bubbling. It uses event bubbling to capture the events on elements which are present anywhere in the domain object model. In jquery the user can make use of the live and die methods for the events delegation which contains a subset of event types. For example: handling event delegation, handling of clicks on any element: Event rebinding usage: When this method is used it requires the user to call the bind method and the added new elements. For example: |
|
| 122. |
What Are The Guidelines For An Application To Follow The Principles Of Progressive Enhancement? |
|
Answer» Progressive enhancement is web development technique that would allow the application to be accessible to any COMPUTER with any Internet connection. For an application to work on the PRINCIPLES of progressive enhancement the following rules / GUIDELINES must be met:
Progressive enhancement is web development technique that would allow the application to be accessible to any computer with any Internet connection. For an application to work on the principles of progressive enhancement the following rules / guidelines must be met: |
|
| 123. |
What Are The Various Ajax Functions ? |
|
Answer» Ajax allows the user to exchange data with a server and update parts of a page without reloading the ENTIRE page. Some of the functions of ajax are as follows:
For example: $.ajaxSetup({"type":"POST", "url":"ajax.php", "success":function(data){ $("#bar") .CSS("background","yellow") .html(data); } });
Ajax allows the user to exchange data with a server and update parts of a page without reloading the entire page. Some of the functions of ajax are as follows: For example: |
|
| 124. |
How Can Images Be Made To Appear Scrolling One Over Another? |
|
Answer» Jquery provides the user with the ability to change the attributes of a property DYNAMICALLY. The jquery slide method can be used to change the height of ELEMENTS gradually. This can be used to give the scroll effect of an image over image. The jquery comprises of the following slide METHODS:
The speed parameter is used to effect the speed of change of the jquery. The parameters for it can be slow, FAST , NORMAL and time in milliseconds. The parameter of callback is used to refer to the name of the function to be executed once the completion of function occurs. Jquery provides the user with the ability to change the attributes of a property dynamically. The jquery slide method can be used to change the height of elements gradually. This can be used to give the scroll effect of an image over image. The jquery comprises of the following slide methods: The speed parameter is used to effect the speed of change of the jquery. The parameters for it can be slow, fast , normal and time in milliseconds. The parameter of callback is used to refer to the name of the function to be executed once the completion of function occurs. |
|
| 125. |
What Are The Types Of Selectors That Are Used In Jquery? Give Examples? |
|
Answer» Jquery enables the user to select specifically the element that is to be effected. jquery allows the user to select in the following WAYS: jquery element selectors: with the use of CSS selectors the users can select the elements of an HTML document. For example: $("p") will select all the <p> elements. jquery attribute selectors: the xpath expressions are USED by jquery to select elements of an html document with defined attributes. For example: $("[href]") is used to select all elements which have an href attribute. Jquery enables the user to select specifically the element that is to be effected. jquery allows the user to select in the following ways: jquery element selectors: with the use of css selectors the users can select the elements of an html document. For example: $("p") will select all the <p> elements. jquery attribute selectors: the xpath expressions are used by jquery to select elements of an html document with defined attributes. For example: $("[href]") is used to select all elements which have an href attribute. |
|
| 126. |
How Can Jquery Library Be Added To Pages? Write A Basic Jquery Code? |
|
Answer» The JQUERY library is a COLLECTION of all the jquery methods. It is stored in the form of a single java script FILE. The format of adding a jquery file to an html PAGE is: <head> An example of a javascript that will hide all the <p> elements in the page. <html> The jquery library is a collection of all the jquery methods. It is stored in the form of a single java script file. The format of adding a jquery file to an html page is: <head> An example of a javascript that will hide all the <p> elements in the page. <html> |
|
| 127. |
When Can You Use Jquery? |
|
Answer» jQuery can be used to developing ajax based applications It can be used to keep the code simple, concise and reusable. It simplifies the process of traversal of HTML DOM TREE. It can also HANDLE events, perform animation, and add the ajax support in WEB applications. jQuery can be used to developing ajax based applications It can be used to keep the code simple, concise and reusable. It simplifies the process of traversal of HTML DOM tree. It can also handle events, perform animation, and add the ajax support in web applications. |
|
| 128. |
Explain How Jquery Works? |
|
Answer» <html> <head> <html> <head> |
|
| 129. |
Why Is Jquery Better Than Javascript? |
Answer»
|
|
| 130. |
Explain The Concepts Of "$ Function" In Jquery With An Example? |
|
Answer» The TYPE of a function is "function". There are a lot of anonymous FUNCTIONS in jquery. $(DOCUMENT).ready(function() {});$("a").click(function() {}); $.ajax({ url: "someurl.php", SUCCESS: function() {} }); The type of a function is "function". There are a lot of anonymous functions in jquery. |
|
| 131. |
Explain The Features Of Jquery? |
|
Answer» Features of jQuery are :
Features of jQuery are : |
|
| 132. |
Advantages Of Jquery? |
|
Answer» The advantages of USING jQuery are:
The advantages of using jQuery are: |
|
| 133. |
What Is Resize() Function In Jquery? |
|
Answer» The resize() FUNCTION is called WHENEVER the browser size is changed. This event can be only USED with $(window). Syntax: .resize([event_data], handler(event_object))
For EXAMPLE $(window).resize(function() {$('#message).text('window is resized to'+$(window).width()+ ‘x’ + $(window).height()); }); The resize() function is called whenever the browser size is changed. This event can be only used with $(window). Syntax: .resize([event_data], handler(event_object)) For example |
|
| 134. |
How To Always Reference Latest Version Of Jquery? |
|
Answer» When you REFERENCE the jQuery on your web page, you have to specify the version number also. <script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js”> </script>Above code will always load the 1.5.1 version of jQuery. If you reference the latest jQuery then you don’t need to change the code EVERY TIME the new version of jQuery is RELEASED. To ACHIEVE this you have to use following code <script type=”text/javascript” src=”http://code.jquery.com/jquery-latest.min.js”> </script>This code will always reference the latest version of jQuery in your page. When you reference the jQuery on your web page, you have to specify the version number also. Above code will always load the 1.5.1 version of jQuery. If you reference the latest jQuery then you don’t need to change the code every time the new version of jQuery is released. To achieve this you have to use following code This code will always reference the latest version of jQuery in your page. |
|
| 135. |
What Is Difference Between Prop And Attr? |
Answer»
For EXAMPLE <input value="My Value" type="text" /> $('input').prop('value', 'Changed Value');
For example <input value="My Value" type="text" /> $('input').prop('value', 'Changed Value'); |
|
| 136. |
What Is Difference Between Sorting String Array And Sorting Numerical Array In Jquery? |
|
Answer» The sort method is used to sort any array elements. It sorts the string elements ALPHABETICALLY. For example $(document).READY(FUNCTION(){ var mylist = [ “APPLE”,”Orange”,”BANANA”]; mylist = mylist.sort(); $(“#mydiv”).html(list.join(“”)); });It will give following output Apple Now we declare a numerical array and use sort() method to sort its elements. $(document).ready(function(){ var mylist = [ “20”,”3””100”,”50”]; mylist = mylist.sort(); $(“#mydiv”).html(list.join(“”)); });It will give following output 100 The sort method is used to sort any array elements. It sorts the string elements alphabetically. For example It will give following output Apple Now we declare a numerical array and use sort() method to sort its elements. It will give following output 100 |
|
| 137. |
What Is Chaining In Jquery? |
Answer»
By using chaining we can write above code as follows $(document).ready(function(){ $('#mydiv').css('color','blue').addClass('myclass').fadeIn('fast'); });
By using chaining we can write above code as follows
|
|
| 138. |
Is Window.onload Is Different From Document.ready()? |
Answer»
|
|
| 139. |
How To Read, Write And Delete Cookies In Jquery? |
Answer»
Read Cookie $.dough("cookie_name"); DELETE cookie $.dough("cookie_name", "remove"); |
|
| 140. |
Explain .empty() Vs .remove() Vs .detach()? |
Answer»
Syntax: $(SELECTOR).empty(); $(selector).remove(); $(selector).detach();Syntax: |
|
| 141. |
What Is Jquery.holdready() Function? |
Answer»
For EXAMPLE $.holdReady(true);$.getScript("xyzplugin.js", function() { $.holdReady(false); });
For example
|
|
| 142. |
What Is The Use Of Param() Method? |
Answer»
empObject.name="Arpit"; empObject.age="24"; empObject.dept=”IT”; $("#clickme").click(function(){ $("span").text($.param(empObject)); }); It will set the text of span to “name=Arpit&age=24&dep=IT” It will set the text of span to “name=Arpit&age=24&dep=IT” |
|
| 143. |
What Is Difference Between $(this) And 'this' In Jquery? |
Answer» $(document).ready(FUNCTION(){
$(‘#clickme’).CLICK(function(){
alert($(this).text());
alert(this.innerText);
});
});
Refer the following example |
|
| 144. |
Explain Slidetoggle() Effect? |
|
Answer» slideToggle() effect is used to give animated sliding effect to an element. Syntax: slideToggle([ DURATION] [, easing] [, callback])
For example $("#clickme").CLICK(function(){$("#mydiv").slideToggle(“slow”, function(){ //run after the animation is complete. }); }); slideToggle() effect is used to give animated sliding effect to an element. Syntax: slideToggle([ duration] [, easing] [, callback]) For example |
|
| 145. |
Explain The Each() Function? |
|
Answer» The each() function specify the function to be called for every matched element. $(SELECTOR).each(function (index, element))
For example $("#clickme").click(function(){$("li").each(function(){ document.write($(this).text()) }); }); This will write the text for each “li” element. The each() function specify the function to be called for every matched element. Syntax: $(selector).each(function (index, element)) For example This will write the text for each “li” element. |
|
| 146. |
Explain Bind() Vs Live() Vs Delegate() Methods? |
Answer»
For example $(document).ready(function(){ $("#myTable").find("TR").live("click",function(){ alert($(this).text()); }); });Above code will not work USING live() method. But using delegate() method we can accomplish this. $(document).ready(function(){ $("#dvContainer")children("table") .delegate("tr","click",function(){ alert($(this).text()); }); });
For example Above code will not work using live() method. But using delegate() method we can accomplish this.
|
|
| 147. |
What Is The Use Of Jquery.data()? |
Answer»
jQuery.data(span, “item”, { val1: 10, val2: "myitem" }); If we want to RETRIEVE the data related to div element and set it to label’s data: $("label:val1").TEXT(jQuery.data(div, "item").val1); jQuery.data(span, “item”, { val1: 10, val2: "myitem" }); If we want to retrieve the data related to div element and set it to label’s data: $("label:val1").text(jQuery.data(div, "item").val1); |
|
| 148. |
Explain Width() Vs Css('width')? |
Answer»
For example $(‘#mydiv’).css(‘width’,’300px’); $(‘#mydiv’).width(100);For example |
|
| 149. |
What Is .siblings() Method In Jquery? |
|
Answer» <UL> For example <ul> <li>item 1</li> <li id="”second_item”">item 2</li> <li CLASS="”myitem”">item 3</li> <li class="”myitem”">item 4</li> </ul> Now we want to find the siblings of the element of id “second_item” and change the text color to Blue : $(‘li.second_item’).siblings().css(‘color’,’blue’); If we want specific sibling elements for example the elements having class “myitem” then we can pass a optional selector: $(‘li.second_item’).siblings(‘.myitem’).css(‘color’,’blue’); For example <ul> <li>item 1</li> <li id="”second_item”">item 2</li> <li class="”myitem”">item 3</li> <li class="”myitem”">item 4</li> </ul> Now we want to find the siblings of the element of id “second_item” and change the text color to Blue : $(‘li.second_item’).siblings().css(‘color’,’blue’); If we want specific sibling elements for example the elements having class “myitem” then we can pass a optional selector: $(‘li.second_item’).siblings(‘.myitem’).css(‘color’,’blue’); |
|
| 150. |
Explain The Animate Function? |
|
Answer» The animate function is used to apply the custom animation effect to elements. Syntax: $(selector).animate({params}, [duration], [easing], [callback])
For example <div id id="clickToAnimate"> Click Me </div> <div id ="mydiv" style=”width:200px; height:300px; position: RELATIVE; right: 20px;"> </div>Following is the jQuery to animate opacity, left offset, and height of the mydiv element $('# clickToAnimate’).click(function() { $('#book').animate({ opacity: 0.30, left: '+=20', height: 'toggle' }, 3000, function() { // run after the animation complete. }); });The animate function is used to apply the custom animation effect to elements. Syntax: $(selector).animate({params}, [duration], [easing], [callback]) For example Following is the jQuery to animate opacity, left offset, and height of the mydiv element |
|