简体   繁体   中英

jquery parents selector - multiple parents in that

Is this a valid syntax:

$("span").parents("li[data='UM'], li[data='Me']")

I want to traverse to parent of span and see if that parent is a li with value of data attribute as "UM" OR li with value of data attribute as "Me". Basically looking for OR operator in parents.

Yes using closest() is definitely the right procedure.

$("span").closest("li[data='UM'], li[data='Me']");

http://api.jquery.com/closest/

使用.closest()代替:

 $("span").closest("li[data='UM'], li[data='Me']")
if ($("span").closest("li").filter("li[data='UM'], li[data='Me']").length) { // there is... }

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