I have the following:
<span class="hello" id="something somemore"> blah blah blah </span>
My regex is not my strongest ability, would appreciate is someone could help me in javascript regex.
I would like to remove everything/anything and including from <span
to >
and then finally just remove the </span>
.
I am using .replace(myregexhere, "");
to replace other items but I am struggling to do the above.
Also if there are easier or better alternatives let me know.
I have the following:
<span class="hello" id="something somemore"> blah blah blah </span>
My regex is not my strongest ability, would appreciate is someone could help me in javascript regex.
I would like to remove everything/anything and including from <span
to >
and then finally just remove the </span>
.
I am using .replace(myregexhere, "");
to replace other items but I am struggling to do the above.
Also if there are easier or better alternatives let me know.
Share Improve this question asked Aug 7, 2012 at 16:28 AnichoAnicho 2,66711 gold badges48 silver badges76 bronze badges 1- why not just remove the element itself? – Phillip Schmidt Commented Aug 7, 2012 at 16:30
4 Answers
Reset to default 6If you really want to use regex replace, try this:
var newstring = oldstring.replace(/<span[^>]*>([^<]*)<\/span>/, "$1");
Note that this doesn't work if any html tags are in between <span>
and </span>
. If you have html tags there then please use something like this instead.
You want something like:
~<span.+?>~
and
~</span>~
Why not use replaceWith()
instead :
var something = $('#something').text();
$('#something').replaceWith(something);
use jQuery:
$('span').remove();
or for each span with class "hello":
$('span .hello').remove();
or for each element with id "something somemore",
$("#something somemore").remove();
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744224940a4563960.html
评论列表(0条)