Tuesday, March 15, 2016

JQuery

1. ID selector and class selector in jQuery:

$("#LoginTextBox") -- Returns element wrapped as jQuery object with id="LoginTextBox" $(".active") -- Returns all elements with CSS class active.
2. How do you find all selected options of HTML select tag?
You can use following jQuery selector to retrieve all selected options of <select> tag with multiple=true :
$('[name=NameOfSelectedTag] :selected')

$('[name=NameOfSelectedTag] :selected').each(function(selected){
        alert($(selected).text());
});

3.
What is difference between detach() and remove() method in jQuery? (answer)
Though both detach() and remove() method is used to remove a DOM element,Main difference between them is that detach() keep track of the last element detached, so that it can be reattached, while remove() method does keep reference of last removed method. This is one of the many jQuery interview question from DOM manipulation. You can also take a look on appendTo() for adding element into DOM.
4.
How do you add and remove CSS classes to an element using jQuery? (answer)
By using addClass() and removeClass() jQuery methods. 

5.
What is difference between jQuery.get() and jQuery.ajax() method?
ajax() method is more powerful and configurable, allows you to specify how long to wait and how to handle error, get() is a specialization to over ajax just to retrieve some data.

No comments:

Post a Comment