This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 4th, 2013  |  syntax: None  |  size: 0.34 KB  |  views: 18  |  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. <div>
  2.     <div>Other Div</div><button>Click Me</button>
  3. </div>
  4. <div>
  5.     <div>Other Div</div><button>Click Me</button>
  6. </div>
  7.        
  8. var buttons = document.body.getElementsByTagName('button');
  9. for(var x = 0; x < buttons.length; x++) {
  10.     buttons[x].onclick = function() {
  11.         this.previousSibling.style.backgroundColor = '#3a6d90';
  12.     }
  13. }
clone this paste RAW Paste Data