Add data hint with jquery
I am trying to add an attribute to an element with jQuery; since my markup is generated on the fly, I cannot directly add this attribute. Why is the below script not adding an attribute? Why doesn't this violin work at will? Here is a fiddle I'm trying to work with some examples of markup.
// 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');
+3
Jim22150
source
to share
1 answer
You need to set the data attribute with .attr()
to really affect the DOM attribute:
jQuery('li#menu-item-75 a').attr('data-tooltip', 'w00t');
:hover
and :before
/ :after
do not work with jQuery selectors.
Demo: http://jsfiddle.net/fkdh8/13/
+3
Blender
source
to share