javascript - how can i add an attribute onClick oto my links generated automatically? -


i add attribute onclick links generated automatically jquery.

i select parent div , search if has link child, add attribute onclick.

it works on localhost not on server there code :

$('div.holder_notify_drop_data,li.holder_notify_drop_data').each(function () {     if ($(this).children('a').hasclass('holder_notify_drop_link')) {         $(this).on('click', function (e) {             var url = $(this).children('a').attr('href');             $(this).children('a').attr('onclick', "openframe('" + url + "','yes')");             e.preventdefault();         });     };) }; 

how can ?

make sure include jquery:

<script src="http://code.jquery.com/jquery-latest.js"></script> 

important: put code inside document-ready function , suggest use jquery click() function instead of way have done, that's okay:

$(document).ready(function () {  $('div.holder_notify_drop_data,li.holder_notify_drop_data').each(function(){ if ($(this).children('a').hasclass('holder_notify_drop_link')){ $(this).on('click',function(e) { var url = $(this).children('a').attr('href'); $(this).children('a').attr('onclick',"openframe('"+url+"','yes')");   e.preventdefault(); }); }; )};  }); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -