Given this table:
<table id="issuetbl">
<tr> <td>aaaa</td> <td><div>whatever</div></td> <td>cccc</td> </tr>
<tr> <td>1111</td><td class="ms-vb"><p>What about rest of line. </p><p> this needs to show uptoo</p></td> <td>2222</td> </tr>
<tr> <td>3333</td> <td><div>else</div></td> <td>4444</td> </tr>
</table>
This jQuery script pull two tds following a match (here 1111).. well at least it did until we put some line feeds int the content. It now only pulls up to the nbsp. Only returns: What about rest of line.
var bodyprefixes = [];
$('#issuetbl td:contains(1111)').nextAll().each(function(i, k) {
var td = $(k), div = td.children();
bodyprefixes.push(div.length ? div.html() : td.html());开发者_如何学C
});
alert(bodyprefixes[0]);
alert(bodyprefixes[1]);
It's a nice solution by https://stackoverflow.com/users/262056/stephen
It's being worked here: http://jsfiddle.net/8RvgA/3/
Anybody know how we can get the full td for 1111?
Something like:
$('#issuetbl td:contains(1111)').parent()
...dunno if this is what you want, I'm just shooting in the dark here.
If you don't need entities:
bodyprefixes.push(td.text());
If you do, yo have to iterate through all children of td
Not quite sure if this is what you want. But if you just want all the data in the same row that has a td with the value '1111', then this should do: http://jsfiddle.net/rkw79/8RvgA/4/
$('#issuetbl td:contains(1111)').nextAll().each(function(i, k) {
bodyprefixes.push($(k).text());
});
Using .text()
will strip out the tags and ignore all the white spaces
updated with tags: http://jsfiddle.net/rkw79/8RvgA/5/
$('#issuetbl td:contains(1111)').nextAll().each(function(i, k) {
bodyprefixes.push($(k).html());
});
精彩评论