Wildcard search of an elements id using jQuery

前端 未结 3 2185
Happy的楠姐
Happy的楠姐 2021-01-07 04:54

I have the following:

if($(\"div[id*=\'*test-*-0-value\']\").length > 0){
    // do stuff
}

Unfortunatly the wild card *test-*-0-v

3条回答
  •  耶瑟儿~
    2021-01-07 05:11

    You can combine the attribute selectors, which are also natively supported in CSS:

    • [id*='...'] - The id must contains ....
    • [id$='...'] - The id must end with ....

    Code:

    if ($("div[id*='test-'][id$='-0-value']").length) {
        // do stuff
    }
    

提交回复
热议问题