jquery - I need to pass numerical arguments to a onclick function in javascript -
i need pass numerical arguments onclick function inside anchor tag in javascript.i wrote code follows not working.
var lat1=latitude; var lon1=longtitude; u.append('<a data-role="button" id="direction" onclick="showdirection(lat1,lon1)" >view directions</a>');
you can use string concatenation that:
u.append('<a data-role="button" id="direction" onclick="showdirection(' + lat1 + ',' + lon1 + ')" >view directions</a>');
that said, onxyz
attributes aren't best way hook event handlers. consider:
var = $('<a data-role="button" id="direction">view directions</a>'); a.appendto(u); a.on("click", showdirection.bind(a[0], lat1, lon1));
...if want values of when hook handler, or
var = $('<a data-role="button" id="direction">view directions</a>'); a.appendto(u); a.on("click", function() { showdirection.call(this, lat1, lon1); });
...if want values of when click occurs.
Comments
Post a Comment