Radek
Radek

Reputation: 11121

How to search for class that has dot in its name?

I have an element with class "4.0.3" how can I search for it?

ff 12.x & latest chrome returns nothing for

console.log($('.4\.0\.3').length);
console.log($(".4.0.3").length);

On the other hand .hasClass() correctly returns if the element got a class that contains .

Upvotes: 0

Views: 254

Answers (2)

BoltClock
BoltClock

Reputation: 724074

As zerkms suggests, you can escape it but you need double backslashes:

$('.4\\.0\\.3')

Or for a less hacky solution, use an attribute selector instead:

$('[class~="4.0.3"]')

Upvotes: 2

zerkms
zerkms

Reputation: 254975

Escape it with double back-slash

$('.4\\.0\\.3')

http://api.jquery.com/category/selectors/

If you wish to use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) as a literal part of a name, you must escape the character with two backslashes: \\

Upvotes: 7

Related Questions