Can i use jQuery to remove part of a text within a div.
Like so:
<div class="entry">
Published May 18th 2011 - Approuved - Expire May 18 th 2012<br>Source: SuperSite
</div>
I would like to remove Approuved - Expire May 18 th 2012
So the result would be:
<div class="entry">
Published May 18th 2011 <br>Source: SuperSite
<开发者_StackOverflow;/div>
You can use jquery to select your element/html, but javascript has a builtin function replace
that will do what you need:
$('div.entry').html($('div.entry')
.html()
.replace('Approuved - Expire May 18 th 2012', ''))
Or using RegExp
:
If what you want to replace starts always with Approuved - Expire
:
$('div.entry').html($('div.entry')
.html()
.replace(/Approuved - Expire[^<]*/, ''))
Try this:
$(".entry").html(function(i, htm){
return htm.split("-")[0];
});
html() can also have a function passed on to it if you want to process the html inside a node and then reset it.
Here is a demo on jsfiddle : http://jsfiddle.net/nKJWn/
$(".entry").html(($(".entry").html().replace("Approuved - Expire May 18 th 2012","")))
精彩评论