jquery - Alternatives to adding JavaScript in anchor tags -


hi stackoverflow community. have question alternatives adding javascript in href of html anchor tags. know poor practice , instead of doing this:

<div id="some_div"><a href="javascript:myfunction();">text</a></div> 

i can this: text

$('#some_div').on("click","a",function(e){   myfunction(); }); 

my question is, how work if have pass variables function? example:

<div id="some_div"><a href="javascript:myfunction('param1','param2')">text</a></div> 

now keep in mind data in param1 , param2 different strings. how handle case? event listener needs receive different data entered anchor tag. how user add param1 , param2 data when use:

<div id="some_div"><a href="#">text</a></div> 

thank in advance.

there lot of ways can it. 1 comes mind use data-* attributes on anchor:

<a href="#" data-param1="param1" data-param2="param2">text</a>  var $this = $(this); myfunction($this.data("param1"), $this.data("param2")); 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -