Pregunta

I'm beginning with jQuery and using it with twig/Symfony 2. I have a little problem : when I use this in a loop :

<a href="#" id="dialog_link"><button type="button" id="button_id" id-uservalue="{{user.id}}" class="btn btn-danger btn-xs">
Delete
</button></a>

Only the 1st Button works, the other just dont. I checked the value of {{user.id}} it changes.

This is the jQuery code :

click : function() {
var id_user = $('#button_id').attr('id-uservalue');

Thanks a lot, internet friends !

¿Fue útil?

Solución

Since id is unique, you need to use class instead:

<a href="#" id="dialog_link"><button type="button" class="button_id" id-uservalue="{{user.id}}" class="btn btn-danger btn-xs">

then you can use:

click : function() {
var id_user = $(this).attr('id-uservalue');
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top