Reputation: 7203
I have the below html stucture:
<td title="Test Info - Displays another Web page on this Web page. The other Web page is presented in an IFrame." class="ms-WPHeaderTd" id="WebPartTitleWPQ2">
<h3 class="ms-standardheader ms-WPTitle" style="width: 778px; text-align: justify; overflow: hidden; text-overflow: ellipsis;" name="MSOFixedWidthTitle" fixedWidth="800px">
<nobr>
<span>
Text - I want this text
<span id="WebPartCaptionWPQ2"/>
And so I am trying to get the text value of the span under the td
with id of: WebPartTitleWPQ2
by doing the next:
var spans = $("#WebPartTitleWPQ2").children("span")
SO then spans.length
is always 0.
What am I doing wrong?
Edit
Doing
$("#WebPartTitleWPQ2").find("span").text()
results in returning of two values both of which are blank
Upvotes: 0
Views: 143
Reputation: 1507
$(selector).children()
only returns direct children of the selected tag. To look for things further down, you can use either
$(selector).find(descendantSelector)
or, in your case,
$('#WebPartTitleWPQ2').find('span')
EDIT: Didn't see the second/nested span. Either of these should work. JSFiddle
$('#WebPartTitleWPQ2').find('span').eq(0).text();
or
$('#WebPartCaptionWPQ2').parent().text();
Upvotes: 6
Reputation: 34416
$('#WebPartTitleWPQ2').find('span').html();
That should get the HTML contained in the first span after this item.
EDIT: I just took another look at the markup you posted - does your span have an ID or is that another span nested within your first span? If not your markup is messed up.
Upvotes: 0