js - using replace method to replace html element

Posted by Rueta on Stack Overflow See other posts from Stack Overflow or by Rueta
Published on 2010-05-14T02:15:16Z Indexed on 2010/05/14 2:24 UTC
Read the original article Hit count: 635

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about replace