Reputation: 335
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 with 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?
Upvotes: 0
Views: 433
Reputation: 117354
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());
});
Upvotes: 1
Reputation: 508
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());
Upvotes: 0