Reputation: 4773
I have my html structure like
<div>
<div class="comments-title-wr clearFix">
<span id="commentsSize" class="comments-title">Some Text</span>
</div>
<div id="testId">
</div>
</div>
I can retrieve testId
and using this I want to replace text inside <span>
tag.
I tried using
$('#testId').parent().closest('.comments-title').text().replace('something else');
but it's not working
Upvotes: 5
Views: 8236
Reputation: 8941
You can use siblings
. http://api.jquery.com/siblings/
.comments-title-wr
and #testId
are siblings. Somehow missed that inner span, answer updated.
$('#testId').siblings('.comments-title-wr').find('.comments-title').text('something else');
Upvotes: 0
Reputation: 148120
Try this,
$('#testId').prev('.comments-title-wr.clearFix').find('.comments-title').text('something else');
Upvotes: 2
Reputation: 123397
$('#testId').prev().children('span').text('something else');
Upvotes: 1
Reputation: 382150
You probably want
$('#testId').parent().find('.comments-title').text('something else');
Upvotes: 2