自定义数据属性上的jQuery选择器不为空 [英] jQuery selectors on custom data attribute that are not empty

查看:776
本文介绍了自定义数据属性上的jQuery选择器不为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为jQuery创建一个简单的自定义工具提示插件,该插件针对每个具有data-custom-tooltipset的元素.因此,类似:

I want to create a simple custom tooltip plugin for jQuery that for every element that has a data-custom-tooltipset. So, something like :

<a href= . . . " data-custom-tooltip="This is my tooltip Text">Hhahaha</a>

<button data-custom-tooltip="This is my tooltip for the button Tex">Haha Button :) </button >

因此,仅当data-custom-tooltip NOT 为空时,才会显示工具提示的功能.

So, the function to display the tooltip would be triggered only if the data-custom-tooltip is NOT empty.

对此足够接近:使用HTML5的自定义数据属性上的jQuery选择器

推荐答案

您可以使用:not( )选择器并删除空的

$('[data-custom-tooltip]:not([data-custom-tooltip=""])')

$('[data-custom-tooltip]').not('[data-custom-tooltip=""]')


还是基于不等于选择器


or based on what @VisioN said in the comments with the Not Equal Selector

var xxx = $('[data-custom-tooltip][data-custom-tooltip!=""]');

这篇关于自定义数据属性上的jQuery选择器不为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆