Is it possible to use a dot in a classname inside Jquery?
$(\'.B.Avf\').toggle();
I need to keep the dot in: B.Avf classname.
Can i som
You can always just use the [attr="val"]
selector for this.
$('[class*="B.Avf"]')
The *=
means "class
contains...". Since this is looking at the attribute directly and there could be more than one class, you don't want to use =
.
There are two ways to select elements that have special selection characters in their identifiers. As Tushar mentioned in a comment, you can use a double backslash (\\
) to escape the special character in query (including both jQuery and document.querySelector), or you can use an attribute selector, as Rocket Hazmat pointed out.
Note that in CSS (that is, an actual stylesheet, not JavaScript), the selector is slightly different. You only need a single backslash to escape the special characters.
Demo below:
// use a double backslash to escape characters in JavaScript query selectors
document.querySelector(".a\\.b").style.backgroundColor = "blue";
//or use an attribute selector!
document.querySelector('[class="a.b"]').style.color = "white";
/* Use a single backslash to escape characters in CSS */
.a\.b{border:1px solid black;}
<div class="a.b">My class name is a.b</div>