I want to use jquery selector for radio button group with array notation
I have radio buttons like this
<input name="show[]" type="radio" value="1" /> Show<br>
<input name="show[]" type="radio" value="0" /> Hide<br>
I want to use jquery selector for the above and tried the following
$("input:radio[name=show[]]").click(function(){
alert(this.value)
})
which is not working
I know we can give like show instead of show[] for the name attribute of radio button
yet IE had problems so by giving with array notation worked in all browsers.
Now i want to give like what i had done and is that possible or is it a different syntax to include array notation?
You need to escape the square brackets in the selector:
$("input:radio[name=show\\[\\]]").click(function(){
alert(this.value)
})
As mentioned By James Allardice, you can also put quotes around the attribute itself to stop the ambiguity:
$("input:radio[name='show[]']").click(function(){
alert(this.value)
})
Better yet, use a class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With