jquery - how parameter inside function works? -


html

<p>this <b>bold</b> paragraph.</p> <button>add</button> 

jquery

$("button").click(function(){     $("p").text(function(i,origtext){       return "old text: " + origtext + " new text: hello world! (index: " + + ")";      });   }); 

i know origtext not called outside function returning value. how?

demo

as docs says

function(index, text)

a function returning text content set. receives index position of element in set , old text value arguments.

and how jquery’s .text() work, internally?


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -