How do you add pseudo classes to elements using jQuery?

You can’t force a certain pseudo-class to apply using jQuery. That’s not how pseudo-classes (especially dynamic pseudo-classes) work, since they’re designed to select based on information that cannot be expressed via the DOM (spec). You have to specify another class to use, then add that class using jQuery instead. Something like this: .element_class_name:hover, .element_class_name.jqhover { … Read more

What is the difference between a pseudo-class and a pseudo-element in CSS?

The CSS 3 selector recommendation is pretty clear about both, but I’ll try to show the differences anyway. Pseudo-classes Official description The pseudo-class concept is introduced to permit selection based on information that lies outside of the document tree or that cannot be expressed using the other simple selectors. A pseudo-class always consists of a … Read more

CSS :selected pseudo class similar to :checked, but for elements

the :checked pseudo-class initially applies to such elements that have the HTML4 selected and checked attributes Source: w3.org So, this CSS works, although styling the color is not possible in every browser: option:checked { color: red; } An example of this in action, hiding the currently selected item from the drop down list. option:checked { … Read more

How can I write a ‘:hover’ condition for ‘a:before’ and ‘a:after’?

This depends on what you’re actually trying to do. If you simply wish to apply styles to a :before pseudo-element when the a element matches a pseudo-class, you need to write a:hover:before or a:visited:before instead. Notice the pseudo-element comes after the pseudo-class (and in fact, at the very end of the entire selector). Notice also … Read more

Why isn’t it possible to combine vendor-specific pseudo-elements/classes into one rule set?

CSS2.1 states: The selector (see also the section on selectors) consists of everything up to (but not including) the first left curly brace ({). A selector always goes together with a declaration block. When a user agent cannot parse the selector (i.e., it is not valid CSS 2.1), it must ignore the selector and the … Read more