1.

Explain The Each() Function?

Answer»

The each() function specify the function to be called for every matched element.

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;”

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.



Discussion

No Comment Found