Jquery : Attribute Start With for current element

896 views Asked by At

Attribute "Start With" in jquery is very simple, but i have a problem How use this attribute for current element? As example i tried:

$('this[id^= "PostTypes"]') 

AND

$(this[id^= "PostTypes"])

But nothing want works.

3

There are 3 answers

0
PSL On BEST ANSWER

Try,

 $('[id^= "PostTypes"]', this); // if you want to find the elements that are descendants of this.

Or if you want to check if the current element is a match then you can use .is(selector):

$(this).is('[id^= "PostTypes"]'); //Check if this element is havind the id startswith PostTypes.

Example:

if($(this).is('[id^= "PostTypes"]')){
   //Current element starts with id PostTypes, do something with it.
}
0
Arun P Johny On

Use filter()

$(this).filter('[id^= "PostTypes"]')
0
tymeJV On

I believe you want:

$('[id^="PostTypes"]', this)