jQuery - 查找具有 rel 属性的元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10015680/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 08:43:02  来源:igfitidea点击:

jQuery - Find element with rel attribute

jqueryhtml

提问by Gerep

I have two kind of elements

我有两种元素

<i rel="tooltip" class='icon-ok'>
<i title="Teste" class='icon-info'>

The first one is a tooltip effect, the second a popover

第一个是工具提示效果,第二个是弹出框

What I'm trying to do is avoid rework so I don't need to create a script based on the class on every html I have.

我想要做的是避免返工,因此我不需要根据我拥有的每个 html 上的类创建脚本。

I did this on my base html:

我在我的基础 html 上做了这个:

$('body').find('i').tooltip();

The problem is that it is adding the tooltip effect on the other <i>elements without the rel attribute.

问题是它在<i>没有 rel 属性的其他元素上添加了工具提示效果。

I need to search for elements with the rel attribute and set the tooltip effect on them.

我需要搜索具有 rel 属性的元素并在它们上设置工具提示效果。

Thanks

谢谢

EDIT

编辑

If I try to do the opposite of what was said on the correct answer, get the <i>elements without the rel attribute. Found the solution here: jQuery selectors - find objects without specified attribute

如果我尝试与正确答案中所说的相反,则获取<i>没有 rel 属性的元素。在这里找到解决方案:jQuery 选择器 - 查找没有指定属性的对象

vrutberg- jQuery("li:not([style])").hide();

弗鲁特贝格-jQuery("li:not([style])").hide();

回答by dku.rajkumar

the exact one

确切的

$('i[rel="tooltip"]').tooltip()

回答by Nudier Mena

yon can select all elements with href att with this selector

你可以使用这个选择器选择所有带有 href att 的元素

$(document).ready(function()
{

$("[rel]")

});