user1464139
user1464139

Reputation:

Is there a way I can simplify this selector

I have the following:

$("#article").on('click', 
    'a[href^="/C"], a[href^="/Java"], a[href^="/T"]', function (event) {

Can this be simplified to not repeat the "href" so many times. Can I use a different kind of regular expression?

Upvotes: 3

Views: 80

Answers (2)

TrL
TrL

Reputation: 30

At least make that one work

$("#article").on("click", 'a[href^="/C"]', 'a[href^="/Java"]', 'a[href^="/T"]', "function(event){}")

Upvotes: 0

Sushanth --
Sushanth --

Reputation: 55740

The best option would be is to give the all the three anchor tags a single class Name..

$("#article").on('click', 'a.planguages', function (event) {

Or any other selector that is common for these three..

Otherwise you cannot remove the href as that looks unique to the anchor tags in context.

Upvotes: 6

Related Questions