开发者

geting tags from textarea with jquery

I want to get some HTML code that are in textarea apply some function to the code replace the src with other url and return the code back to the textarea when I click on button. I would like to do this wit开发者_如何学JAVAh jquery.

<textarea  id="proverka"><div id='sd'> <img src="/images/panorami/53.jpg"></div></textarea> <input type="button" id="mes1" name="btn_cancel"
                value="change" />

Is this possible?


You can create an jquery-object of the text inside the textarea, manipulate it and write the html back:

$('#mes1').click(function(){
var tmp= $('<root/>').append($('#proverka').val())[0];
    $('img',tmp).attr('src','another.url');
   $('#proverka').val($(tmp).html());
});


One possible way to do this:

  1. Create a new element from a textarea value

    $('#dummy').html($('#proverka').val());

  2. Change the SRC attribute of the new element

    $('#dummy img').attr("src", 'newvalue');

  3. Retrieve HTML of the new element and put it back to the textarea

    $('#proverka').val($('#dummy').html());

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜