HighDots Forums  

click Event Problem with appended html element

jQuery jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. jQuery is designed to change the way that you write JavaScript.


Discuss click Event Problem with appended html element in the jQuery forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ndes
 
Posts: n/a

Default click Event Problem with appended html element - 11-07-2009 , 07:49 AM






Hi! I was wondering if i made something wrong or this dont works in
general. I have a drop down list that "onChange" loads some data an
pops a list of img+text

$('#selectDisplay').change(function(){
..........
//LOOP
$("#btnDisplay").append('<img class="btnDisp"
value="'+respObj.jsonarray[i]['id']+'" style="vertical-align: bottom;
padding: 0 6px;" src="img/fam/add.png" />'+respObj.jsonarray[i]['name']
+'<br />');
......
});


I also have a general even on $(document).ready(function() {

$('.btnDisp').click(function(){
//DO SOMETHING ex.
alert("working");
});

The problem is that on dynamic generated img's (custom btns) the
onClick Alert doesnt work. But it works on static .btnDisp imgs that
loads with the html...

So what can I do for something like this?
Thanks in advance!

Reply With Quote
  #2  
Old   
Leonardo K
 
Posts: n/a

Default Re: [jQuery] click Event Problem with appended html element - 11-07-2009 , 05:10 PM






Look the live event: http://docs.jquery.com/Events/live#typefn

On Sat, Nov 7, 2009 at 10:49, ndes <fevgatos (AT) gmail (DOT) com> wrote:

Quote:
Hi! I was wondering if i made something wrong or this dont works in
general. I have a drop down list that "onChange" loads some data an
pops a list of img+text

$('#selectDisplay').change(function(){
.........
//LOOP
$("#btnDisplay").append('<img class="btnDisp"
value="'+respObj.jsonarray[i]['id']+'" style="vertical-align: bottom;
padding: 0 6px;" src="img/fam/add.png" />'+respObj.jsonarray[i]['name']
+'<br />');
.....
});


I also have a general even on $(document).ready(function() {

$('.btnDisp').click(function(){
//DO SOMETHING ex.
alert("working");
});

The problem is that on dynamic generated img's (custom btns) the
onClick Alert doesnt work. But it works on static .btnDisp imgs that
loads with the html...

So what can I do for something like this?
Thanks in advance!

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.