javascript - jQuery .html() anonymous function return oldHtml -


fiddle: http://jsfiddle.net/bplumb/znmf5/1/

this lack of understanding on part, trying run anonymous function .html() custom code , return old html string value variable. isn't returning html expect returning jquery object based on selector used.

var oldhtml = $('#test').html(function(index, oldhtml){     //some custom code here     return oldhtml; }); console.log(oldhtml);  

i thought return html way works in normal function call.

var someotherhtml = getoldhtml();  console.log(someotherhtml);  function getoldhtml(){     return $('#test').html(); } 

what not understanding jquery when comes this?

$(...).html(function) returns original jquery object, not html in selected element.

what return in function set new html of selected element.

$(collection).html(function(){     return "i'm new html!"; }); // results in elements in collection receiving html ("i'm new html!") // equivalent to: // $(collection).html("i'm new html!"); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -