javascript - JQ event handler on a click -


i have dynamically generated content contains links on ajax call success. links generated this.

$('#mysomething').append('<a href = "' + url + '" target = "_blank" class = "myclickclass">' + name + '</a>'); 

i tried

$('a.myclickclass').click(),  $('.myclickclass').click(),  $('.myclickclass').on('click', 'a', function({})),  

and

$(document).on('click', '.myclickclass a', function (e) {} ); 

but nothing seems happen. new tab opened, event ignored.

use $(".myclickclass")[0].click()

you can directly attach event new anchor.

$('body').append($('<a href = "http://www.google.de" class = "myclickclass">test</a>')          .click(function() {              alert("hey there");          }));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <body></body>

the message printed.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -