I have a html.twig file with this
{% set num= 1%}
{% for idea in ideas %}
<div class="add">
<a href="#"> Comentar </a>|<a href="#" rel="like{{num}}"> Tomado </a>|<a href="#">Valorar</a>
</div>
</div>
{% set num= num +1 %}
{% endfor %}
so depend of the number of ideas I have more o less likes, like this
<a rel="like1" href="#"> Tomado </a>
<a rel="like2" href="#"> Tomado </a>
<a rel="like3" href="#"> Tomado </a>
If I want to do a click in jquery,but how I indicate the number of link, the value of num variable
$("a[rel='like']").click(function(){
alert($("a[rel='like']").text());
});
any idea!
I am going to assume you want the value of the
relattribute.If that’s true, you should try this: http://jsfiddle.net/kakashi/Uqqpr/
My solution uses the
attrmethod to obtain the value of therelattribute.Update
It appears you want the number contained in the rel attribute, i.e. you want “1” when it’s “like1”, “2” when it’s “like2”, etc.
If so, this solution will do that:
http://jsfiddle.net/kakashi/Uqqpr/1/
*Update 2 — accounting for multiple digit “likes” *
http://jsfiddle.net/kakashi/Uqqpr/2/
This version uses regular expressions to capture the number at the end.