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:
Create a new element from a textarea value
$('#dummy').html($('#proverka').val());
Change the SRC attribute of the new element
$('#dummy img').attr("src", 'newvalue');
Retrieve HTML of the new element and put it back to the textarea
$('#proverka').val($('#dummy').html());
精彩评论