js - using replace method to replace html element
- by Rueta
hi everyone!
i have a question. I have a work this morning but i don't know how to do it.
My work here (html):
<div class="demo">
<p>this is demo text</p>
</div>
here is my JS :
var tempdata = $(".demo").text();
var replacedata = tempdata.replace("text","<span>1234</span>");
Look everything ok. but result is : this is demo <span>1234</span>. this isn't my result i want. How to make in this string become a HTMLelement by using replace method?