jQuery Selector How to - Select element by class name








Question

We would like to know how to select element by class name.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from w ww  .  ja va2 s  .  c o  m-->
    $(document).ready(function() {
      $("div.left_arrow_background").click(function(){
        console.log('clicked!');
      });
    });
});
</script>
</head>
<body>
  <div>
    <div class='left_arrow_background'> LEFT</div>
  </div>
</body>
</html>

The code above is rendered as follows: