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]
The [attribute^="value"] selector is used to select elements with the specified attribute, whose value starts with the specified value. The following example selects all elements with a class attribute value that starts with "top": Note: The value does not have to be a whole word!
[attribute$=”value”] Selector: This selector is used to select all the elements whose attribute value ends with the specified value. The value doesn't need to be a whole word. [attribute*=”value”] Selector: This selector selects all the elements whose attribute value contains the specified value present anywhere.
Updated on July 03, 2019. The dollar sign ($) and the underscore (_) characters are JavaScript identifiers, which just means that they identify an object in the same way a name would. The objects they identify include things such as variables, functions, properties, events, and objects.
To use this selector, add a tilde (~) before the equals sign. For example, img[alt~="art"] will select images with the alt text “abstract art” and “art show”, but not “athlete starting a new sport” (which the “contains” selector would select). Value starts with: attribute value starts with the selected term.
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]');
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