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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -