简体   繁体   English

获取具有特定类的同级div且未禁用

[英]Get a sibling div with specific class and is not disable

I want to find a div with a class associated with it, but it must not be disabled. 我想找到一个具有与之关联的类的div,但是一定不能禁用它。 I am using following code for getting the next sibling, but it will return the next element with the "menuDiv" class. 我正在使用以下代码来获取下一个同级,但是它将返回带有“ menuDiv”类的下一个元素。

var nextDiv=jQuery('div.subMenuBarhover').nextAll('.menuDiv:first');

but now I need the element which is not disable and id of all element is unkown. 但是现在我需要不被禁用的元素,并且所有元素的id都是未知的。

How can I achieve this? 我该如何实现?

You said you are using a custom attribute to mark a div as disabled. 您说您正在使用自定义属性将div标记为已禁用。 I would recommend to always use data-* attributes for custom attributes, ie 我建议始终将data-*属性用于自定义属性,即

<div data-disabled="true">

To select the next div without that attribute, use the negation pseudo class (aka :not selector) and the attribute selector: 要选择不带该属性的下一个div ,请使用否定伪类(aka :not选择器)属性选择器:

jQuery('div.subMenuBarhover').nextAll('.menuDiv:not([data-disabled]):first');

If you want to find the next element where the data-disabled attribute has a certain value, use the attribute-equals selector: 如果要查找data-disabled属性具有特定值的下一个元素,请使用attribute-equals选择器:

jQuery('div.subMenuBarhover').nextAll('.menuDiv[data-disabled=false):first');

In general, have a look at all the existing selectors have try them out! 一般来说, 看看所有现有的选择器都可以尝试一下!

Try adding . 尝试添加。 not(':disabled') to your code as required. not(':disabled')到您的代码。

not

disabled selector 禁用的选择器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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