Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 1.59 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Change the div background when onmouseover another div
  2. .one:hover ~ .two {background:salmon;}
  3.        
  4. .one:hover ~ ul .three {background: lightblue;}
  5.        
  6. document.getElementById('XYZ').onmouseover = function(){
  7.     //Do stuff here
  8. }
  9.        
  10. <div class="div1"></div>
  11. <div class="div2"></div>
  12.        
  13. .div2 {
  14.     background: #FFF url(/path/to/mouseOUTImage) top left no-repeat;
  15.  }
  16.  .div2MouseOver {
  17.     background: #FFF url(/path/to/mouseOVERImage) top left no-repeat;
  18.  }
  19.        
  20. $('.div1')
  21. .mouseenter(function() {
  22.   $('.div2').addClass('div2MouseOver');
  23. })
  24. . mouseleave(function() {
  25.   $('.div2').removeClass('div2MouseOver');
  26. });
  27.        
  28. (function () {
  29.  
  30.     //change the value of div1 with your first div box
  31.     var div1 = document.getElementById('div1');
  32.     var div2 = document.getElementById('div2');
  33.     var defBC = div2.style.backgroundColor;
  34.  
  35.     addEventHandler(div1, 'mouseover', function () {
  36.         div2.style.backgroundColor= 'black';
  37.     });
  38.  
  39.     addEventHandler(div1, 'mouseout', function () {
  40.         div2.style.backgroundColor= defBC;
  41.     });
  42.  
  43.  
  44.     function addEventHandler(el, eType, handler) {
  45.         if (el.addEventListener) { // W3C, FF  
  46.             el.addEventListener(eType, handler, false);
  47.         } else if (el.attachEvent) { // IE  
  48.             el.attachEvent('on' + eType, function() {
  49.                 handler.call(el);
  50.             });
  51.         }
  52.     }
  53.  
  54. })();
  55.        
  56. var bgcolor;
  57. $("#id_of_first_div").hover(function(){
  58.       bgcolor = $("#id_of_div_2").css('backgroundColor');
  59.       $("#id_of_div_2").css('backgroundColor', '#ffcc00');
  60.    },
  61.    function(){
  62.       $("#id_of_div_2").css('backgroundColor', bgcolor);
  63. });