I try to get all the texts in my html data that the user enters
I have html as below
<em>first part</em> of texts here <table> ...... ...... </table> <em>second part</em> of texts
I am using jquery
project =[]; $(htmlData).contents().each(function(){ if($(this).is('table')){ //do something with table }else{ if(this.nodeType === 3) { // Will only select element nodes project.push($(this).text()); }else if(this.nodeType === 1){ project.push(this.outerHTML); } } }
array ends as
array(0=>'<em>first part</em>', 2=>'of texts here',3=>'<em>second part</em>',4=>'of texts')
I was hoping to get an array similar to the following
array(0=>'<em>first part</em>of texts here',1=>'<em>second part</em>of texts');
How to do it? Thanks for the help!
source share