views:

1142

answers:

3

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

A: 

Because it wasn't ever defined? Where's the html? Are you sure you're targeting the right element?

meder
A: 

$(this) will give you whatever element has the id of "#forwardStep", so for this example to work it should be a link or anchor, but you said it was a button.

I don't think a button can have a rel attribute. If you are trying to get the rel attribute from a link you'll need to selct that link rather than "this". e.g. $('#theLinkId').attr('rel').

You should add the HTML to this question.

Lance Fisher
+1  A: 

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);
 })
})
fudgey