Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- onmouseover="document.getElementsByClassName().style.background='color'"
- document.getElementsByClassName()
- ^_______
- <th id="colorswitcher A" onmouseover="document.getElementsByClassName('a').style.background='red'">a</th>
- <th id="colorswitcher B" onmouseover="document.getElementsByClassName('a').style.background='blue'">b</th>
- window.onload=function(){
- var aColl = document.getElementsByClassName('a'); //Cache the collection here, so that even a new element added with the same class later we can avoid qurying this again by using the cached collection.
- var bColl = document.getElementsByClassName('b');
- document.getElementById('A').addEventListener('mouseover', function(){
- changeColor(aColl, 'red');
- });
- document.getElementById('B').addEventListener('mouseover', function(){
- changeColor(bColl, 'blue');
- });
- }
- function changeColor(coll, color){
- for(var i=0, len=coll.length; i<len; i++)
- {
- coll[i].style["background-color"] = color;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement