views:

162

answers:

1

Apologies if this has been asked already, I can't find the answer in the jQuery docs.

How would I select all .tooltip classes which have a [title] attribute, and the [title] attribute is not empty?

In other words, select these:

<a href="#" class="tooltip" title="YES">Foo</a>
<span class="tooltip" title="YES">Bar</span>

But not these:

<a href="#" class="tooltip" title="">Empty title attribute.</a>
<span class="tooltip">No title attribute.</span>
+3  A: 

Try this selector:

.tooltip[title]:not([title=""])
Gumbo
It's so easy when you know how. =) Thanks once again, Gumbo.
Jeff
I've found that this also seems to work, although it's possible the plugin I'm using does some filtering, too: `$( '.tooltip[title!=""]' )`
Jeff
@Jeff: Nice, didn’t know that attribute selector since it’s not part of CSS 3. But mine is CSS 3 compliant.
Gumbo
@Gumbo: What part of my selector has anything to do with CSS 3? I think what it says is "all .tooltip classes with a title attribute not equal to an empty string."
Jeff
@Jeff: There is no attribute selector like `[attr!="value"]`. The negation needs to be expressed with `:not()`: `:not([attr="value"])`.
Gumbo