Skip to main content

Posts

Showing posts with the label bind

jQuery how to bind onclick event to dynamically added HTML element

I want to bind an onclick event to an element I insert dynamically with jQuery But It never runs the binded function. I'd be happy if you can point out why this example is not working and how I can get it to run properly: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="da" lang="da"> <head> <title>test of click binding</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> jQuery(function(){ close_link = $('<a class="" href="#">Click here to see an alert</a>'); close_link.bind("click", function(){ alert('hello from binde