jQuery Form How to - Style select input box








Question

We would like to know how to style select input box.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.5.2.js'></script>
<style type='text/css'>
option {<!--   ww w .  ja  va 2  s  . c  o  m-->
  background: orange;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    $('#selectbox').css({
        'background': 'blue',
        'color':'white'
    });
});
</script>
</head>
<body>
  <select id="selectbox" class='ui-state-error'>
    <option>123</option>
    <option>456</option>
    <option>789</option>
  </select>
</body>
</html>

The code above is rendered as follows: