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 trs table , loop through trs 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

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -