开发者

Why does the jQuery element[] selector not work in this case?

开发者 https://www.devze.com 2023-03-27 22:52 出处:网络
I hav开发者_C百科e lots of form inputs with automatically generated IDs which look like the following:

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 ids are unique, this should suffice:

$("[id$='_txtQuantity']").val("666");
0

精彩评论

暂无评论...
验证码 换一张
取 消