Jquery - attr() et removeAttr() - disabled sur un button
Bonjour à tous,
Je cherche à développer 2 boutons où le premier modifie le deuxième tout tout particulièrement le premier doit modifier l'attribut disabled="disabled" du second.
J'ai trouvé un post : http://www.developpez.net/forums/d71...-d-formulaire/ qui traite un peu de ce sujet.
Bon concernant mon code (écrit sou Symfony donc utilisant twig) :
Le HTML
Code:
1 2 3 4 5 6
| <button type="button" class="btn btn-default btn-xs" onclick="putOnline({{ association.id }})" title="Mettre en ligne">
<span name="actionBtn" id="{{ association.id }}" class="fa fa-play"></span>
</button>
<button type="button" name="viewBtn" id="{{ association.id }}" class="btn btn-default btn-xs" onClick="window.location.href='{{ path('geograph_progasso_fiche', {'id': association.id }) }}'" title="Voir en ligne" disabled="disabled">
<span class="fa fa-eye"></span>
</button> |
Le javascript :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| function putOnline(id){
// Quel est l'état du champ
var action = $('span[name="actionBtn"]#'+id).attr('class');
$.ajax({
type: 'get',
url: Routing.generate('putOnline', {'id': id}),
beforeSend: function(){
},
success: function(){
if (action == "fa fa-play"){
$('span[name="actionBtn"]#'+id).attr('class', 'fa fa-stop');
$('button[name="viewBtn"]#'+id).removeAttr('disabled');
$('#online').text(Number($('#online').text()) + 1);
$('#offline').text(Number($('#offline').text()) - 1);
} else {
$('span[name="actionBtn"]#'+id).attr('class', "fa fa-play");
$('button[name="viewBtn"]#'+id).attr('disabled', "disabled");
$('#online').text(Number($('#online').text()) - 1);
$('#offline').text(Number($('#offline').text()) + 1);
}
}
})
} |
Je parviens à modifier le premier bouton et notamment son icone mais n'arrive pas à modifier l'attribut disabled...
Merci par avance pour vos réponses.