Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get rel value of clicked element

hi im trying to get the rel value of a button that is click:

function forwardStep()
{
    $("#forwardStep").bind("click", function(){
        var page = $(this).attr('rel');

thats pretty much the basis but is return "undifined". Do you know why?

Regards Phil Jackson

like image 801
Phil Jackson Avatar asked Sep 27 '09 05:09

Phil Jackson


1 Answers

If you're using a button with an ID, then you shouldn't have to get any extra data from the rel attribute since the function is unique to your button.

But if you have other reasons, then you just need to make sure your button itself has a rel attribute defined, e.g.

<input id="forwardStep" rel="test" type="button" value="forward" />

and your function is closed properly

$(document).ready(function(){
 $('#forwardStep').bind('click',function(){
  var page = $(this).attr('rel');
  alert(page);
 })
})
like image 186
Mottie Avatar answered Nov 08 '22 23:11

Mottie