jQuery Selector How to - Style element by id content








Question

We would like to know how to style element by id content.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
div[id^='imgHere'] {
  background: red;
}<!--   w  ww .  j a  v  a2  s.c  o  m-->
</style>
</head>
<body>
  <div id="imgHere1">Div 1</div>
  <div id="imgNotHere1">Div 2</div>
  <div>Div 3</div>
  <div id="imgHere2">Div 4</div>
</body>
</html>

The code above is rendered as follows: