Attribute selectors

It is possible to select elements with specified attributesExtra information added to an element. and with specified values of attributes:

  • Use tagname[attribute] to select elements with the given tag name and attribute.
  • Use tagname[attribute=value] to select elements with the given tag name, attribute, and value.

In the example, notice the following:

  • The list item without a class attribute is not blue.
  • Only the list items with class attribute value odd have a background colour of yellow.

Note:

Hints:

  • undefined
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
<!DOCTYPE html>
<html lang="en">
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
li[class{
    colorblue;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX