Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  12] [ 6]  / answers: 1 / hits: 21757  / 12 Years ago, sun, december 2, 2012, 12:00:00

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?


More From » jquery

 Answers
23

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:




[#81661] Friday, November 30, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
casandra

Total Points: 334
Total Questions: 93
Total Answers: 104

Location: Denmark
Member since Tue, Jul 19, 2022
2 Years ago
casandra questions
Thu, Feb 25, 21, 00:00, 3 Years ago
Mon, Jul 6, 20, 00:00, 4 Years ago
Thu, May 21, 20, 00:00, 4 Years ago
Tue, Sep 17, 19, 00:00, 5 Years ago
;