Why does the jQuery element[] selector not work in this case?
I hav开发者_C百科e lots of form inputs with automatically generated IDs which look like the following:
<input type="text" id="ctl00_ctl00_rptVariants_ctl00_txtQuantity" />
If I use the following jQuery selector, it finds the element:
$("#ctl00_ctl00_rptVariants_ctl02_txtQuantity").val("666");
However if I use either of the following, no element is found, yet all the documentation implies that it should work:
$("element[id='ctl00_ctl00_rptVariants_ctl02_txtQuantity']").val("666");
or
$("element[id$='_txtQuantity']").val("666");
The goal is to select all input fields where their IDs end in _txtQuantity.
Thanks!
the element
refers to the tag.
In this case use input
like this:
$("input[id$='_txtQuantity']").val("666");
Since they are not <element>
tags but <input>
ones, you should use:
$("input[id$='_txtQuantity']").val("666");
However, since id
s are unique, this should suffice:
$("[id$='_txtQuantity']").val("666");
精彩评论