jQuery Selector How to - Select by class alternatives








Question

We would like to know how to select by class alternatives.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-2.0.0.js'></script>
<style type='text/css'>
.activeMenu {<!--from   w  w w  .  j a va2  s. c  om-->
  color: Red;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    var a = $('[id*="firstName"]')
    console.log(a.get());
    a.css( "background-color", "yellow" );
});
</script>
</head>
<body>
  <span id="span.firstName">asdf</span>
  <input id="input.firstName" value="asdf" />
</body>
</html>

The code above is rendered as follows: