Want to replace text inside span of parent div
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 get testId, and using this, I want to replace the text inside the tag <span>.
I tried to use
$('#testId').parent().closest('.comments-title').text().replace('something else');
but it does not work
+5
5 answers
You can use siblings. http://api.jquery.com/siblings/
.comments-title-wrand #testIdare brothers and sisters. Somehow I skipped this internal interval, the answer was updated.
$('#testId').siblings('.comments-title-wr').find('.comments-title').text('something else');
0