简体   繁体   中英

Jquery : Attribute Start With for current element

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.

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.
}

使用filter()

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

我相信你想要:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM