jquery - How do dynamically add an J Query onclick event to a carousel banner -


i have dynamic carousel banner on homepage (i have no control on html expect can add href, image ref , can add id link each carousel banner) can add an event first carousel banner not others. think it's because html doesn't exist banners when document loaded execpt first 1 carousel banner dynamic , changes every couple of seconds. i've added id second banner of testid , tried below code:

      $(document).ready(function(){       $('#testid').click(function(){       _gaq.push(['_trackevent', 'cbanner', 'idtest',$(this).attr('href'),0,true]);        });        }); 

but onclick event still not working.

thanks

since buttons created dynamically dom, click event not available these buttons. in case, event delegation attach event.

try this

$(document).on('click','#yourdynamicbuttonid',function(){  }); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -