eimkasp

Javascript event listners examples

Oct 3rd, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.addEventListener("DOMContentLoaded", function() {
  2.     document.querySelectorAll('.photo')
  3.  
  4.     var htmlElement = document.getElementsByClassName("photo");
  5.     console.log(htmlElement);
  6.  
  7.    
  8.     /*for(var i = 0; i < htmlElement.length; i++) {
  9.         htmlElement[i].classList.toggle("raudonasTekastas");
  10.     }*/
  11.  
  12. for(var i = 0; i < htmlElement.length; i++) {
  13.     htmlElement[i].addEventListener("click", function(){
  14.         this.classList.add("raudonasTekastas");
  15.         console.log(this);
  16.     });
  17. }
  18.  
  19. });
Advertisement
Add Comment
Please, Sign In to add comment