Guru Guru - 10 months ago 32
HTML Question

select element starting with class name and contain part of string

I'm gonna select element with class but named 'path_from' etc.

Let me show you example

<div class='path_from_5_to_6'></div>
<div class='_6'></div>
<div class='path_from_6_to_5'></div>
<div class='path_from_3_to_2'></div>

I want to select element which class is start with path_from but contain '_6'

How can I do this?


You can use [class^="path_from"][class*="_6"] attribute selector

  • [class^="path_from"] - class starts with path_from
  • [class*="_6"] - class contains _6

[class^="path_from"][class*="_6"] {
  background: blue;
<div class='path_from_5_to_6'>DIV</div>
<div class='_6'>DIV</div>
<div class='path_from_6_to_5'>DIV</div>
<div class='path_from_3_to_2'>DIV</div>