How to add <br /> after Artikler with jquery
The following source is created dynamically.
I'd like to add
<br />
a开发者_开发知识库fter Artikler, to become
Artikler<br />.
Source
<div id="shopping">
<p><!--TEXT:--> <A HREF="cart-8.asp" CLASS="longsum">7 Artikler, verdi: 10 199,00</A></p>
</div>
I think I need to use
.after('<br />');
but I am not sure how to get Artikler.
7 will be changed dynamically.
The jQuery DOM manipulation functions (such as after()
) work specifically on DOM elements, and in this case your entire block of text is a single element.
A better approach is to get the text out of the element:
var text = $("a.longsum").html();
Then do your string replace:
text = text.replace("Artikler", "Artikler<br />");
and put the result back into the element:
$("a.longsum").html(text);
"7 Artikler, verdi: 10 199,00".replace("Artikler", "Artikler<br />");
this should do the thing if i got you correctly
精彩评论