I am trying to get every texts in my html
data which is input by the user
I have html
like the following
<em>first part</em> of texts here
<table>
......
......
</table>
<em>second part</em> of texts
I use 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);
}
}
}
the array
ends up like
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 like the following
array(0=>'<em>first part</em>of texts here',1=>'<em>second part</em>of texts');
How do I accomplish this? Thanks for the help!