html - using jquery to replace text delete my span and his class -
i want replace text contained span class, code, thing happen span class deleted
here's code:
    $("input.textinput").on("keyup", function () {         target = $(this).attr("lang").replace("text", "div");         $("." + target).text($(this).val());     });   and here's example div:ì (before replace):
<div class="targetdiv"><span class="test"> text replaced </span></div>   and how looks after script (after replace):
<div class="targetdiv">replacing text</div>   edit
ok, here's fiddle:
you're directly targeting div, , calling .text() replaces entire content of div text.
change line:
$("." + target).text($(this).val());   to
$("." + target + " span").text($(this).val());   live example: http://jsfiddle.net/mtg9b/
Comments
Post a Comment