oknasir
oknasir

Reputation: 13

Remove link from textarea and remove image from div by click on remove link

I am new to jQuery and want this problem solve. Thanks in advance for that.

i made my code sample in fiddle. in ths code sample i have a textarea and a div.

<div id="divfordisplay"></div>

This div display all the links of images which are in textarea.

Now my problem is that i want a remove image link on image and by clicking on this remove link this image should remove from div and also remove link from textarea.

Upvotes: 1

Views: 407

Answers (2)

Wolf
Wolf

Reputation: 2150

Try this code. Demo here

jQuery(document).ready(function() {
    var imguploadvaluesdis = jQuery('#img_upload_value').val().split('\n');
    for( var i=0; i<imguploadvaluesdis.length; i++){
        jQuery('#divfordisplay').append('<img src="' + imguploadvaluesdis[i] + '" alt="" />');

    }
    $('img').click( function() {
        var newVal =$('#img_upload_value').val().replace($(this).attr('src'),'');
        $('#img_upload_value').val(newVal);
        $(this).remove();
    });
});

Upvotes: 1

Ram
Ram

Reputation: 144689

$('#divfordisplay').on('click', 'img', function(){
   var link = this.src;
   $(this).remove();
   $('#img_upload_value').val(function(i, v){
       return v.replace(link, '');
   });   
});

http://jsfiddle.net/SpHeT/

Upvotes: 2

Related Questions