Codejoy
Codejoy

Reputation: 3816

how to jquery selection on ids using like a * to match

I have a bunch of ids for radio buttons on my page:

id="scores_0" id="scores_1" etc etc.. I am new to jquery and wonder if there is a way to like select anything that sort of matches that.

$("#scores_*").css("border", "2px none black")

etc ?
or do i have to dynamically regex it somehow?

Upvotes: 0

Views: 45

Answers (2)

Sridhar Narasimhan
Sridhar Narasimhan

Reputation: 2653

Try the below

$('input[id^=scores_]'); //^= StartsWith
$('input[id*=scores_]'); //*= Contains

Upvotes: 4

wirey00
wirey00

Reputation: 33661

Read here about jQuery selectors http://api.jquery.com/category/selectors/

$('[id^=scores_]') // <-- this selects all id starting with scores_

Upvotes: 2

Related Questions