jqueryjquery-attributes

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.


Solution

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