Hbaecklund Hbaecklund - 5 months ago 23
jQuery Question

Change text to h1 with jquery?

How do I make the

2990 kr
text into an
h1
?

<div class="productPrice">
<span>2 990 kr</span>
</div>


Alt 1 http://api.jquery.com/html/

$(".productPrice").html("h1");


Alt 2 http://api.jquery.com/text/

$(".productPrice").text("h1");

Answer

.wrapInner() method can be used.

Wrap an HTML structure around the content of each element in the set of matched elements.

$('.productPrice span').wrapInner('<h1 />')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="productPrice">
<span>2 990 kr</span>
</div>

Comments