Guru Guru - 1 year ago 74
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?

Answer Source

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>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download