Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find all elements by part of the id attribute

I was wondering if this was possible:

I have a set of divs, each with an ID ending in '_font', e.g 'body_font', 'heading_font', 'tagline_font', etc.

Is there a way to grab those elements by searching for a common portion of their names, in this case '_font' so I can later manipulate them using jQuery?

like image 801
mousesports Avatar asked Dec 02 '12 15:12

mousesports


1 Answers

You can use an "attribute ends-with" selector:

var elems = $("div[id$='_font']");

If you spend some time browsing the jQuery API you should be able to answer questions like this yourself without having to post on Stack Overflow.

Other selectors that might come in useful:

  • Attribute starts-with selector
  • Attribute contains selector
  • Attribute equals selector
like image 142
James Allardice Avatar answered Oct 22 '22 02:10

James Allardice