Badr Hari
Badr Hari

Reputation: 8374

Find a selector starting with a letter

I'd like to find a CSS selector or selectors starting with a given letter. Is this possible?

.myClass[id^=' ... '] 

(... represents any letter)

Upvotes: 1

Views: 97

Answers (2)

Ram
Ram

Reputation: 144659

There is no pre-defined css selector for this. You can use the filter method:

$('.myClass[id]').filter(function() {
    return /[A-Za-z]/.test(this.id[0]);
});

You can also define a pseudo-selector:

jQuery.extend(jQuery.expr[':'], { 
    youNameIt: function(a) { 
        return /[A-Za-z]/.test(a.id[0]);
    }    
}); 

$('.myClass:youNameIt');

Upvotes: 2

Yogesh Sharma
Yogesh Sharma

Reputation: 2017

Yes you can try this

element[att^=val]

Please see http://www.css3.info/preview/attribute-selectors/ Link for reference

Upvotes: 1

Related Questions