开发者

jquery select from within element

开发者 https://www.devze.com 2023-03-19 07:17 出处:网络
How do I do this (but in a way that works): $(\"MyElem\").get(\"[id$=\'Date\']\").datepicker(开发者_运维技巧);

How do I do this (but in a way that works):

$("MyElem").get("[id$='Date']").datepicker(开发者_运维技巧);

Essentially I'm trying to select all elements that end with the word "Date" in the id within the context of a given parent element.

So this should be interpreted as:

  1. Get "MyElem".
  2. From "MyElem" search all children recursively and find id's that end with "Date".
  3. For each item in the results of step 2 call datepicker on that element


Why not using find method:

$('#myelem').find('[id&=Date]').datepicker();

Or why not using a better selector:

$('#myelem *[id$=Date]').datepicker();


Use find [docs]:

$(elementReference).find("[id$='Date']").datepicker();

where elementReference is either a DOM element or a selector. If it already is a jQuery object, then just do elementReference.find(....

0

精彩评论

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