javascript - jQuery selector for HTML5 data attributes - Stack Overflow

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742364838a4430106.html

相关推荐

  • javascript - jQuery selector for HTML5 data attributes - Stack Overflow

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

    9小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信