How to get rel value for clicked element

hi im trying to get rel value by pressing a button:

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

pretty much the foundation, but returns "unifined." Do you know, why?

Regards, Phil Jackson

+6
jquery attributes return-value
source share
3 answers

If you use a button with an identifier, you will not need to get additional data from the rel attribute, since the function is unique to your button.

But if you have other reasons, you just need to make sure that your button itself has a certain rel attribute, for example.

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

and your function is closed correctly

 $(document).ready(function(){ $('#forwardStep').bind('click',function(){ var page = $(this).attr('rel'); alert(page); }) }) 
+15
source share

Because it has never been determined? Where is the html? Are you sure you configured the correct item?

0
source share

$ (this) will provide you with any element with the identifier "#forwardStep", so for this example to work, it should be a link or an anchor, but you said that this is a button.

I do not think that a button can have a rel attribute. If you are trying to get the rel attribute from a link, you need to remove that link, not "this". e.g. $ ('# TheLinkId'). Atr ('rel.').

You should add HTML code to this question.

0
source share

All Articles