javascript - add data-tooltip with jquery - Stack Overflow

I'm trying to add an attribute to an element with jQuery; since my markup is created on-the-fly I

I'm trying to add an attribute to an element with jQuery; since my markup is created on-the-fly I can't directly add the attribute. Why is the below script not adding the attribute? Why is this fiddle not functioning as desired? Here is the fiddle I am trying to get working with some sample markup included.

// set the tooltip content
jQuery('li#menu-item-75 a:hover:before').prop('tooltipText', 'w00t');
jQuery('li#menu-item-75 a:hover:after').prop('tooltipText', 'w00t');

I'm trying to add an attribute to an element with jQuery; since my markup is created on-the-fly I can't directly add the attribute. Why is the below script not adding the attribute? Why is this fiddle not functioning as desired? Here is the fiddle I am trying to get working with some sample markup included.

// set the tooltip content
jQuery('li#menu-item-75 a:hover:before').prop('tooltipText', 'w00t');
jQuery('li#menu-item-75 a:hover:after').prop('tooltipText', 'w00t');
Share Improve this question edited Jan 31, 2013 at 23:56 Jim22150 asked Jan 31, 2013 at 23:45 Jim22150Jim22150 5112 gold badges8 silver badges22 bronze badges 3
  • 1 You forgot to select jQuery on your JSFiddle... – Hanlet Escaño Commented Jan 31, 2013 at 23:51
  • Thanks, fixed. That's not what the problem was though. – Jim22150 Commented Jan 31, 2013 at 23:57
  • 1 Glad you could fix it :) – Hanlet Escaño Commented Jan 31, 2013 at 23:57
Add a ment  | 

1 Answer 1

Reset to default 3

You'll have to set the data attribute with .attr() in order for the DOM attribute to actually be affected:

jQuery('li#menu-item-75 a').attr('data-tooltip', 'w00t');

:hover and :before/:after don't work with jQuery selectors.

Demo: http://jsfiddle/fkdh8/13/

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

相关推荐

  • javascript - add data-tooltip with jquery - Stack Overflow

    I'm trying to add an attribute to an element with jQuery; since my markup is created on-the-fly I

    7天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信