AMZMA
AMZMA

Reputation: 7

insert text to textarea

case: if i click red image > add new div, then if i click green image > insert text to textarea

how can i make this work?
http://jsfiddle.net/AMZMA/tNt7t/11/

i know if i make it to this
http://jsfiddle.net/AMZMA/tNt7t/9/
it works

but it will load image in background cause i'm using display:none
i only want load image when i click the red image

sorry for my bad english :D

Upvotes: 0

Views: 95

Answers (1)

dlock
dlock

Reputation: 9577

You are using click() event on #image which will apply to all the images that currently exist in the document and it will not apply on images that you dynamically add in the future. You may use delegate() or on() to listen for the click event for all #image elements that are there now or in the future.

  $(document).on('click', "#image",function(event){
        var test = $(event.target).attr("title");
        $(".text").focus().val(test);
    });

http://jsfiddle.net/tNt7t/20/


This might be helpful:

Upvotes: 1

Related Questions