NoWar
NoWar

Reputation: 37672

How to find a DOM element by part of its ID with jQuery

I need to find <div id="sometrack123456"></div> by part of its id "track" using jQuery.

How I can do it?

Thank you!

Upvotes: 2

Views: 230

Answers (3)

gen_Eric
gen_Eric

Reputation: 227310

Use the contains selector.

$('div[id*="track"]')

Upvotes: 1

PinnyM
PinnyM

Reputation: 35541

You can try this:

$('div[id*="track"]')

See http://api.jquery.com/category/selectors for more info.

Upvotes: 2

Kevin B
Kevin B

Reputation: 95057

Try the attribute contains selector [attr*="str"]

$('div[id*="track"]').doSomething();

The quote order is important.

Upvotes: 5

Related Questions