最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery selector for HTML5 data attributes - Stack Overflow

programmeradmin0浏览0评论

I have this button with multiple data attributes, and i want to hide it by selecting it based on class and two data attributes.

<a href='#' class='wishlist-icon' data-wish-name='product' data-wish-url='/product'>Button</a>

$(".wishlist-icon [data-wish-name='product'] [data-wish-url='/product']").hide();

I don't know why this selector doesn't work.

DEMO

I have this button with multiple data attributes, and i want to hide it by selecting it based on class and two data attributes.

<a href='#' class='wishlist-icon' data-wish-name='product' data-wish-url='/product'>Button</a>

$(".wishlist-icon [data-wish-name='product'] [data-wish-url='/product']").hide();

I don't know why this selector doesn't work.

DEMO

Share Improve this question asked Sep 14, 2013 at 10:27 DušanDušan 4982 gold badges9 silver badges23 bronze badges 1
  • 1 The space is the descendant selector. You are looking for an element [data-wish-url='/product'] inside an element [data-wish-name='product'] inside an element .wishlist-icon. If you want to select an element based on multiple selectors, you have to write them together. – Felix Kling Commented Sep 14, 2013 at 10:43
Add a ment  | 

1 Answer 1

Reset to default 7

Just remove the space between the selector.

$(".wishlist-icon[data-wish-name='product'][data-wish-url='/product']").hide();

Js Fiddle Demo

发布评论

评论列表(0)

  1. 暂无评论