Sunday 26 February 2017

JQuery interview questions Part 3

1. Ques: What is JQuery.noConflict?
Answer:
jQuery no-conflict just overcome the conflicts between the different js frameworks or libraries.
When we use jQuery no-conflict mode, we are replacing the $ to a new variable and assigning to jQuery some other JavaScript libraries.Use the noConflict() method to specify a new name for the jQuery variable.

2. Ques: What is $(document).ready() function ?
Answer:
The ready event occurs when the DOM (document object model) has been loaded.Because this event occurs after the document is ready, it is a good place to have all other jQuery events and functions. The ready() method specifies what happens when a ready event occurs.


3. Ques: What is difference between prop() and attr() in Jquery ?
attr()
  • Get the value of an attribute for the first element in the set of matched elements.
  • gives you the value of element as it was defines in the html on page load
prop()
  • Get the value of a property for the first element in the set of matched elements.
  • It gives the updated values of elements which is modified via javascript/jquery
4. Ques: What is each() function in jQuery ?
Answer:
jQuery.each()is funtion which loop through a collection (object type or array type).it iterated by their index position and value in Array-like objects.


5. Ques: What is Dojo?
Answer:
Dojo is a third-party javascript toolkit for creating rich featured applications. Dojo is an Open Source DHTML toolkit written in JavaScript. It builds on several contributed code bases (nWidgets, Burstlib, f(m)), which is why we refer to it sometimes as a “unified” toolkit. Dojo aims to solve some long-standing historical problems with DHTML which prevented mass adoption of dynamic web application development.


6. Ques: Can we set session variables from JavaScript ?
Answer:
It's not possible to set any session variables directly from javascript as it is purely a client side technology.


7. Ques: Explain the each() function ?
Answer:
each() is the jquery function and it is used to iterate over jquery matched object list.
each() is a traversing method which works only jquery objects.
syntax :
$(selector).each(function(index,element))
  •  “index” is the index position of the selector.
  •  “selector” specifies the current selector where we can use “this” selector also.
  •   In the case when we need to stop the each loop early then we can use “return false;”
Example:
<script>
  $(document).ready(function(){
      $("button").click(function(){
          $("li").each(function(){
              alert($(this).text())
        });
    });
});
</script>


8. Ques: What is the use of param() method ?
Answer:
The param() method is used to represent an array or an object in serialize manner.While making an ajax request we can use these serialize values in the query strings of URL.
Syntax: $.param(object | array, boolValue)
“object | array” specifies an array or an object to be serialized.
“boolValue” specifies whether to use the traditional style of param serialization or not.

For example:
personObj=new Object();
empObject.name="Vijay";
empObject.age="29";
empObject.dept=”Marketing”;
$("#clickme").click(function()
{
     $("span").text($.param(empObject));
});


9. Ques: What is difference between id selector and class selector in jquery ?
Answer:

  • Id are unique in html page
  • Each element can have only one id
  • Each page can have only one element with that id
  • Classes are not unique in html page 
  • You can use the same class on multiple elements.
  • You can use multiple classes on the same element.

ex:
<div id="Body">
<h1>Tile of pages</h1>
<p class="para">here i am showing my blog</p>
<p class="para">css class applied here</p>
</div>

No comments:

Post a Comment

Thank you for comment