J query interview

What is Jquery?
 
jquery is javascript library which required a jquery.js file. After that you can write the jquery as fallows. It uses "$" as the short hand to write jquery code.
Simple Syntax is 

Code:
$(document).ready(function()
{
function body
});
 
Advantages of jQuery ?
The advantages of using jQuery are:

  • JavaScript enhancement without the overhead of learning new syntax
  • Ability to keep the code simple, clear, readable and reusable
  • Eradication of the requirement of writing repetitious and complex loops and DOM scripting library calls
 
What $("div.tutoriz") will select?
All the div element with tutoriz class.
What are the fastest selectors in Jquery?
ID and element selectors are the fastest selectors
 
What are the slower selecoters in Jquery?
Class selectors are slower
 
Which one is faster Jquery ID selector or JavaScript getElementById()?
JavaScript getElementById() is faster than Jquery Id ($("#elementID")) selector
 
Where Jquery code execute? On client browser or server browser?
On client browser
 
Write the code for selecting the 1st div element, 4th div element last div, and for even and odd div elemets also. one by one?
<div class="questions">
<div class="box"> Question</div>
<div class="box"> Question</div>
<div class="box"> Question</div>
<div class="box"> Question</div>
<div class="box"> Question</div>
<div class="box"> Question</div>
</div>
Code for first div : $("div.questions > div:first").css("color", "red");
Code for 4th div : $("div.questions > div:nth-child(4)").css("color", "red");
Code for last div : $("div.questions > div:last").css("color", "red");
Code for even div : $("div.questions > div:even").css("color", "red");
Code for odd div : $("div.questions > div:odd").css("color", "red");
 
 
Write the code for select second last div element?
Code for second last div : $("div.questions > div::nth-last-child(2)").css("color", "red");
  
What are the advantages of using jQuery over JavaScript in ASP.NET web application
Below are the advatages of using jQery over JavaScript
a>.Jquery is well written optimised javascript code so
it will be faster in execution unless we write same standard optimised javascript code.
b>.Jquery is concise java script code ,means minimal ammount of code
is to be written for the same functionality than the javascript.
c>;.Javascript related Development is fast using Jquery because most of the
functionality is already written in the library and we just need to use that.
d>;.Jquery has cross browser support ,so we save time for supporting all the browsers.
 
What is Chaining in jQuery?
In jQuery, Chaining means to connect multiple functions, events on selectors. look at Sample Code 1 and 2.
Sample Code 1
$(document).ready(function(){
$('#dvContent').addClass('dummy');
$('#dvContent').css('color', 'red');
$('#dvContent').fadeIn('slow');
});​

Sample Code 2 (using Chaining)
$(document).ready(function(){
$('#dvContent').addClass('dummy')
.css('color', 'red')
.fadeIn('slow');    
});​
 
 
How to check Jquery UI loaded or not?
// Checking if jQuery UI is loaded or not
Code:
if($.ui){
// jQuery UI is loaded
}else {
// jQuery UI is not loaded
}
 
 
Write the code for setting datetimepicker on textbox click.
If below is our textbox
<input type="text" id="abc" name=%26quot%3Bacc%26quot%3B value="Select Date" />
then Jquery code will be
$("#abc").datepicker();
 
If you have a table, how you will apply the two differt color on alternate rows using Jquery?
Vikas Ahlawat
Edwin George
Rohit Khurana
Gyan Singh
Ans :
<script src="jquery.js"></script>
<script>
$(document).ready(function()
{
  $("tr:even").css("background-color", "#f4f4f8");
  $("tr:odd").css("background-color", "#ffffff");
});
</script>  
 
 
Name the Jquery method which is used to hide selected elements?
.hide()
 
Name the Jquery methods which are used for apply css class? 
$("#Id1").addClass('YourClassName'); // for apply class
$("#Id1").removeClass('YourClassName'); // for remove class
 
What is the use of attr() method in Jquery?
The attr() method sets or returns attributes and values of the selected elements.
When this method is used to return the attribute value, it returns the value of the first matched element.
When this method is used to set attribute values, it sets one or more attribute/value pairs for the set of matched elements.

Code
$(selector).attr(attribute) //it will return the value of an attribute
$(selector).attr(attribute,value) //it will set the value of an attribute
$(selector).attr({attribute:value, attribute:value,...}) //for set multiple attribute
 
 
Tell the name of jQuery method which is used to perform an asynchronous HTTP request?
jQuery.ajax()
 
What is the use of jquery load() method?
The jQuery load() method is a powerful AJAX method.
The load() method loads data from a server and puts the returned data into the selected element without reload the complate page.
Ex:The following example loads the content of the file "demo_test.txt" into a specific <div> element
$("#div1").load("demo_test.txt");
 
 
Can we use our own specific charactor in the place of $ sigh in Jquery?
Yes
You can also create your own shortcut very easily. The noConflict() method returns a reference to jQuery, that you can save in a variable, for later use. Here is an example:
Code
var vikas = $.noConflict();
vikas(document).ready(function(){
vikas("button").click(function(){
vikas("p").text("jQuery is still working!");
});
});
 
Name the 5 Jquery events?
jQuery Events
jQuery click() event.
jQuery dblclick() event.
jQuery mouseenter() event.
jQuery mouseleave() event.
jQuery mousedown() event.
jQuery mouseup() event.
jQuery hover() event.
jQuery focus() and blur() events.

Comments

Popular posts from this blog

How to write Pure java script Program?