mplungjan
mplungjan

Reputation: 178421

Selector to get all text from tag EXCEPT text in specific nested tag

Objective: Extract all the text in a tag EXCEPT from a header tag.

Input html: (generated by JSP - I have no control over the format or spaces) - can be 500 or more rows

<td class="aaaColumn">    <h4>Header text:</h4>      some data         <br />       some more data [XX].   </td>

What have I tried:

var o = "aaa";
var arr = $.trim(
$("."+o+"Column").text()
.replace(/[\[\]]/g," "))
.split(" ");

Current output:

IE gives me

Header
text:some
data
some
more
data
XX

and Fx gives me

Header
text:
some
data
some
more
data
XX

What I need:

IE and Fx (and all other browsers)

some
data
some
more
data
XX

So something like (I am guessing)

$("."+o+"Column :not('h4')").text()

Upvotes: 1

Views: 187

Answers (1)

Pranay Rana
Pranay Rana

Reputation: 176956

This will give you the output you want just have look to it.....

DEMO

$("#aaaColumn").clone()    //clone the element
         .children() //select all the children
         .remove()   //remove all the children
         .end()  //again go back to selected element
         .text();    //get the text of element     

Upvotes: 1

Related Questions