I have the following HTML element:
<input type="checkbox" name="ctl00$ContentPH$ucFuncionEdit1$ckEsMenu" />
How can I select all elements with the same name using jQuery, the following fails:
jQuery('[name=ctl00$ContentPH$ucFuncionEdit1$ckEsMenu]');
The previous line of code raise the following error:
Error: Syntax error, unrecognized expression:
[name=ctl00$$ContentPH$$ucFuncionEdit1$$ckEsMenu]
You quote the value:
jQuery ('[name="ctl00$ContentPH$ucFuncionEdit1$ckEsMenu"]');
When dealing with attribute selectors, it's best to always quote the value (although if the value is a single word containing only the letters A-Z [case insensitive] and the digits 0-9 [but not starting with a digit], you can get away without).
You can escape the $
sign with with two backslashes (\\
):
jQuery('[name=ctl00\\$ContentPH\\$ucFuncionEdit1\\$ckEsMenu]');
you are talking about clientid so you can do it in 2 ways:
1. when your js code in the same page where your html:
jQuery('#<%=ckEsMenu.ClientID%>').click();
2. when your js code is in separeted file:
jQuery("input[id$=ckEsMenu]").click();