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.
Just 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"]')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With