Advertisement
Guest User

Untitled

a guest
Oct 8th, 2014
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. onmouseover="document.getElementsByClassName().style.background='color'"
  2.  
  3. document.getElementsByClassName()
  4. ^_______
  5.  
  6. <th id="colorswitcher A" onmouseover="document.getElementsByClassName('a').style.background='red'">a</th>
  7. <th id="colorswitcher B" onmouseover="document.getElementsByClassName('a').style.background='blue'">b</th>
  8.  
  9. window.onload=function(){
  10. 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.
  11. var bColl = document.getElementsByClassName('b');
  12.  
  13. document.getElementById('A').addEventListener('mouseover', function(){
  14. changeColor(aColl, 'red');
  15. });
  16.  
  17. document.getElementById('B').addEventListener('mouseover', function(){
  18. changeColor(bColl, 'blue');
  19. });
  20. }
  21. function changeColor(coll, color){
  22.  
  23. for(var i=0, len=coll.length; i<len; i++)
  24. {
  25. coll[i].style["background-color"] = color;
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement