ph4x35ccb

eventos javascript

Dec 8th, 2021 (edited)
527
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const animaisList = document.querySelector('.animais-lista');
  2. function calback(even){
  3.      console.log(even.target);
  4. }
  5.  
  6. animaisList.addEventListener('click',calback);
  7.  
  8.  
  9. const img =  document.querySelector('img');
  10. function calback(){
  11.     console.log("Clicou");
  12. }
  13. img.addEventListener('click',calback);
  14.  
  15. const animaislista = document.querySelector('.animais-lista');
  16. function callback(event){
  17.     console.log(event.target)
  18. }
  19. animaislista.addEventListener('click', callback)
  20. const linkExterno = document.querySelector('a[href^="http"]');
  21. function callback_(event){
  22.     event.preventDefault();
  23.     console.log(this.getAttribute('href'));
  24.     console.log(event.target.href);
  25. }
  26. linkExterno.addEventListener('click',callback_);
  27.  
  28. const h1 = document.querySelector("h1");
  29.  
  30. function mouseEvent(event){
  31.     console.log(event.type, event);
  32. }
  33. h1.addEventListener('mouseenter',mouseEvent);
  34. window.addEventListener('scroll',mouseEvent)
  35. window.addEventListener('resize',mouseEvent);
  36. window.addEventListener('keydown', mouseEvent);
  37.  
  38.  
  39. function keyBoard(event){
  40.     if(event.key=='a'){
  41.         console.log(event.key);
  42.     }else if(event.key=='v'){
  43.         console.log(event.key);
  44.     }
  45. }
  46. window.addEventListener('keydown',keyBoard);
  47.  
  48.  
  49. function key(event){
  50.     if(event.key=='f'){
  51.         document.body.classList.toggle('fullscrem');
  52.     }
  53. }
  54. window.addEventListener('keydown',key);
  55.  
  56. function handleimg(event){
  57.     console.log(event.target.getAttribute('src'))
  58. }
  59. const imgs = document.querySelectorAll('img');
  60. imgs.forEach((event)=>{
  61.     event.addEventListener('click',handleimg)
  62. })
  63. const links = document.querySelectorAll('a[href^="#"]');
  64. function handleLink(event){
  65.     event.preventDefault();
  66.     links.forEach((link)=>{
  67.         link.classList.remove("ativo");
  68.     })
  69.     event.currentTarget.classList.add('ativo');
  70. }
  71. links.forEach((link)=>{
  72.     link.addEventListener('click',handleLink)
  73. })
  74. function handlElemento(event){
  75.     //console.log(event.currentTarget.remove())
  76. }
  77. const todoselementos = document.querySelectorAll('body *');
  78. todoselementos.forEach((elemento)=>{
  79.     elemento.addEventListener('click',handlElemento)
  80. });
  81.  
  82. function bigText(event){
  83.     if(event.key==='t'){
  84.         document.documentElement.classList.toggle('textoMaior');
  85.     }
  86. }
  87. window.addEventListener('keydown',bigText)
  88.  
RAW Paste Data