jquery select from within element

风流意气都作罢 提交于 2020-02-16 05:27:29

问题


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

回答1:


Why not using find method:

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

Or why not using a better selector:

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



回答2:


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(....



来源:https://stackoverflow.com/questions/6623359/jquery-select-from-within-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!