RadioButtons hooked up to my change() jQuery event don't fire
Here's my code:
<script type="text/javascript">
$('input[name="paymenttype"]').change(function () {
alert("works!"); // This doesn't fire.
});
</script>
<div id="paymentselector">
<label>
<input name="paymenttype" value="deposit" type="radio" />Deposito
</label>
<label>
<input name="paymenttype" value="creditcard" type="radio" />Tarjeta de Credito
<开发者_如何学Go;/label>
</div>
According to the documentation, this should work: http://api.jquery.com/attribute-equals-selector/
In the change() event, the alert isn't fired.
Is something wrong in my Javascript code?
You could try adding a document ready handler -
$(document).ready(function() {
$('input[name="paymenttype"]').change(function () {
alert("works!"); // This doesn't fire.
});
});
Well, right off the bat, you need to wrap your JS in a $(document).ready(function(){ ... });
block. When the JS is run, the element it's trying to access doesn't exist yet.
精彩评论