Home Interview Questions and Answers JQuery Interview Questions and Answers For Graduates Part-5

jquery41.How to select all elements using jQuery?
$(‘*’) selects all elements available in a DOM.

42.How to select multiple elements using jQuery?
$(‘E, F, G’) selects the combined results of all the specified selectors E, F or G where selectors can be any valid jQuery selector.

43.How to get attributes of an element using jQuery?
The attr() method can be used to fetch the value of an attribute from the first element in the matched set.

44.How to set attributes of an element using jQuery?
The attr(name, value) method can be used to set the named attribute onto all elements in the wrapped set using the passed value.

45.How can you apply a style on an element using jQuery?
The addClass( classes ) method can be used to apply defined style sheets onto all the matched elements. You can specify multiple classes separated by space.

46.How to remove an attribute from each of the matched elements using jQuery?
The removeAttr( name ) method can be used to remove an attribute from each of the matched elements.

47.How to know if a specified class is present on at least one of the set of matched elements using jQuery?
The hasClass( class ) method returns true if the specified class is present on at least one of the set of matched elements.

48.How to remove all or the specified class(es) from the set of matched elements using jQuery?
The removeClass(class) method remove all or the specified class(es) from the set of matched elements.

49.How to add the specified class if it is not present, remove the specified class if it is present using jQuery?
The toggleClass(class) method adds the specified class if it is not present, removes the specified class if it is present.

50.How to get the html contents (innerHTML) of an element using jQuery?
The html() method gets the html contents (innerHTML) of the first matched element.

You may also like

Leave a Comment