Unable to loop through elements inside an HTML string using JQuery 2.1.4 -
i using jquery function retrieve string containing html code , process locally. string is:
var return_data = '<div><tr><td>blah</td><td>more blah</td></tr><tr><td>blah</td><td>more blah</td></tr><tr><td>blah</td><td>more blah</td></tr><span id="morerows">1</span></div>';
(i understand <tr>
should come inside <table>
, not inside <div>
how need input reason , should inconsequential issue @ hand.) need loop through each <tr>
, output contents console. trying this:
$(return_data).find("tr").each(function(){ var mydata = $(this).html(); console.log(mydata); });
but above nothing; no output on console. sure, changed console.log()
input "hello" , turns out, control isn't entering loop. possibly causing this?
you may need following. wrap tr
s table
, loop through tr
s instead of div
.
var return_data = '<div><table><tr><td>blah</td><td>more blah</td></tr><tr><td>blah</td><td>more blah</td></tr><tr><td>blah</td><td>more blah</td></tr></table><span id="morerows">1</span></div>'; $(return_data).find("tr").each(function () { var mydata = $(this).html(); console.log(mydata); });
Comments
Post a Comment