Find and remove text in div
I have a rss-feed where every post ends with a link wrapped in a paragraph. I want it deleted.
Example:
<p>I want to keep this</p>
<p>I want to <strong>find</strong> and <a href="#">r开发者_开发百科emove</a> this string</p>
Well, deleting the last paragraph can be done like:
$(document).ready(function () {
$('p:last').remove();
});
If an RSS newsitem has its own class, like class="RssRow"
, you could use each()
to remove the last child for each row:
$('.RssRow').each(function() {
$(this).find('p:last').remove();
});
If you want to do this with jQuery and it's always the last paragraph (and wrapped in div like you said in the title), then this might work.
$("div p:last-child").remove();
This finds last <p>
in <div>
and removes it.
How about this then?:
If you have structure like this:
<div id="feed1">
<p>I want to keep this</p>
<p>I want to <strong>find</strong> and <a href="#">remove</a> this string</p>
</div>
<div id="feed2">
<p>I want to keep this</p>
<p>I want to <strong>find</strong> and <a href="#">remove</a> this string</p>
</div>
Then you can delete each last paragraph containing a link with this:
$(document).ready(function () {
$("p:last-child > a").parent().remove();
});
This would result to output:
I want to keep this
I want to keep this
精彩评论