-1

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>

OR

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

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

Close enough to this : jQuery selectors on custom data attributes using HTML5

Community
  • 1
  • 1
JanvierDesigns
  • 71
  • 1
  • 10
  • Try this link...http://stackoverflow.com/questions/4146502/jquery-selectors-on-custom-data-attributes-on-html5 – DoctorMick Mar 04 '14 at 16:44
  • The question is: what is the function to display the tooltip so it would be triggered only if the data-custom-tooltip is NOT empty ?? – JanvierDesigns Mar 04 '14 at 16:48

3 Answers3

3

You can use :not() selector and remove the empty ones

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

or

$('[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!=""]');
Community
  • 1
  • 1
epascarello
  • 204,599
  • 20
  • 195
  • 236
1

use like this

$("[data-custom-tooltip]:not([data-custom-tooltip='']").click(function(){alert("clicked");});

fiddle

Anoop Joshi P
  • 25,373
  • 8
  • 32
  • 53
0

Try

.filter()

var tooltip_el = $('[data-custom-tooltip]').filter(function () {
    return $.trim($(this).data('custom-tooltip')) != '';
});
Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107