javascript - Can't get the id name using onClick? -
http://wthdesign.net/test/test.html
what i'm trying append id name url, i'm getting "#undefined" instead?
the script i'm using:
function generateurl() { var currentid = $(this).attr('id'); document.location.hash = currentid; console.log($(this)); }
inside html:
<a id="abc" onclick="generateurl()" >this anchor btn</a>
if debug, you'll find this
in context window object. can pass this
function so:
function generateurl(el) { var currentid = $(el).attr('id'); document.location.hash = currentid; }
<a id="abc" onclick="generateurl(this)" >this anchor btn</a>
alternatively, can use jquery replace inline onclick
so:
$("#abc").click(function() { var currentid = $(this).attr('id'); document.location.hash = currentid; }
Comments
Post a Comment