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,324
  • 3
  • 17
  • 43
Kamini
  • 690
  • 2
  • 12
  • 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
  • 29,061
  • 5
  • 39
  • 52