There are times when I have a choice between using a CSS element:hover or JavaScript onmouseover to control the appearance of html elements on a page. Consider the following scenario where a div wraps an input
<div>
<input id="input">
</div>
I want the input to change background color when the mouse cursor hovers over the div. The CSS approach is
<style>
input {background-color:White;}
div:hover input {background-color:Blue;}
</style>
<div><input></div>
The JavaScript approach is
<div onmouseover="document.getElementById('input').style.backgroundColor='Blue';">
<input id="input">
</div>
What are the advantages and disadvantages of each approach? Does the CSS approach work well with most web browsers? Is JavaScript slower than css?