0

I am working with java and js. Query is I am adding div dynamically from java code and it is getting displayed on the jsp but I want onclick event on that div id. And its not working

tried this:

   $("#moreoption" ).on( "click", function() {
               alert( "Goodbye!" ); // jQuery 1.3+
             }); 

//added class instead of id and in a href

   $(".moreoption" ).on( "click",'a', function() {
               alert( "Goodbye!" ); // jQuery 1.3+
             });


$("#dd" ).live( "click", function() {
           alert( "Goodbye!" ); // jQuery 1.3+
         });

Please help.

VBMali
  • 1,360
  • 3
  • 19
  • 46
Kamini
  • 690
  • 2
  • 13
  • 36

2 Answers2

1
$(document.body).on("click","#dd",function(){
alert( "Goodbye!" );
})
-1

Delegate with a parent container such as document

$(document).on("click", "#moreoption", function() {
    alert("Goodbye!"); // jQuery 1.3+
});
AmmarCSE
  • 30,079
  • 5
  • 45
  • 53