$

Check radio button whose value = $ programmatically

The switch group is defined:

<input type="radio" name="type0" value="$">$<input type="radio" name="type0" value="%">% 

It is necessary to check the first switch whose value = $ .

The problem is that the code below does not do this. Need to somehow avoid $

 $('input[type=radio][value=$]').attr('checked','checked'); 
+4
source share
4 answers
 $('input[type=radio][value="$"]').first().attr('checked','checked'); 
+8
source

this works for me, enclose the selector in double quotes and the selector of attributes in single

 $("input[type=radio][value='$']").attr('checked','checked'); 

http://jsfiddle.net/BuvKT/

+2
source

Escape the dollar with \\ :

 $('input[type=radio][value=\\$]:first').attr('checked','checked'); 

Code: http://jsfiddle.net/E6uBw/3/

+2
source
 $('input[type="radio"][name="type0"][value="$"]:first').prop('checked', true); 
0
source

Source: https://habr.com/ru/post/1390238/


All Articles