rob.m
rob.m

Reputation: 10571

How to target a title attribute in a link with jQuery?

I am trying to hide the title of a link popping out in firefox but I am getting an error if I do the following:

$('a["title"]').on('mouseenter', function(e){
    e.preventDefault();
});

Console

Uncaught Error: Syntax error, unrecognized expression: a["title"]

Upvotes: 2

Views: 107

Answers (1)

Josh Crozier
Josh Crozier

Reputation: 240868

Omit the double quotes in the attribute selector. It should be a[title]:

$('a[title]').on('mouseenter', function(e){
    e.preventDefault();
});

The quotes usually represent an attribute's value. For instance, a[title="value"].

For further reference, the correct syntax for an attribute selector can be found here.

Upvotes: 3

Related Questions