Javascript Style How to - Change Background color for text








Question

We would like to know how to change Background color for text.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
div {<!-- www  . jav  a2  s .  c  o m-->
  padding: 20px;
}
</style>
<script type='text/javascript'>
window.onload=function(){
document.getElementById('styling').style.backgroundColor = "#FFFF00";
}
</script>
</head>
<body>
  <div>
    <span id="styling">HelloHowAreyou</span>
  </div>
</body>
</html>

The code above is rendered as follows: