Search code examples
radio-buttonjqueryeventtrigger

jQuery radio button change function not being triggered when it should


I have a problem with this jQuery Change function:

<input type="radio" name="words" value="8" checked><span class="word">word1</span>
<input type="radio" name="words" value="6"><span class="word">word2</span>

$("input[@name='words']:checked").change(function(){
    alert("test");
});

The problem is that the event gets only triggered when I click the first option (value=8) which is checked by default.

How Can I trigger the event when clicking any other option?

Please note: I have tried the above function on both Chrome and Firefox and I have the same problem.

Thanks!


Solution

  • should be $("input[name='words']").change(function(){