admin管理员组文章数量:1336293
I have a div:
<div id="picture_contents_12356_title"></div>
The '12356' is a unique id that is auto-generated and I need to have it there. How can I create a jQuery selector for an id that has "picture_contents" AND "title"?
I know you can do [id*="picture_contents"]
but I also need to check if it contains "title" as well. How do I do create the AND logic there?
I was thinking maybe extracting the id into a variable and checking indexOf("picture_contents")
and indexOf("title")
but I was wondering if there was a better way.
I have a div:
<div id="picture_contents_12356_title"></div>
The '12356' is a unique id that is auto-generated and I need to have it there. How can I create a jQuery selector for an id that has "picture_contents" AND "title"?
I know you can do [id*="picture_contents"]
but I also need to check if it contains "title" as well. How do I do create the AND logic there?
I was thinking maybe extracting the id into a variable and checking indexOf("picture_contents")
and indexOf("title")
but I was wondering if there was a better way.
-
7
$('[id*="picture_contents"][id*="title"]')
– Shaunak D Commented Apr 6, 2015 at 17:56
2 Answers
Reset to default 9Just keep adding attribute based selectors [attribute*=".."]
In your case,
$('[id*="picture_contents"][id*="title"]')
Suggestion: if the pattern of words is constant, you could use
^=
: starts-with or$=
: ends-with selector too.
For,
<div id="picture_contents_12356_title"></div>
Use,
$('[id^="picture_contents"][id$="title"]')
Alternatively you could give all of the appropriate divs a class and refer to that instead.
本文标签: javascriptHow to check if id contains multiple wordsStack Overflow
版权声明:本文标题:javascript - How to check if id contains multiple words? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742405842a2468802.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论