NickAndNick

Обработчик для всех картинок страницы

Aug 4th, 2016
282
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!doctype html>
  2. <html lang="ru">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <title>Картинки</title>
  6.   <style>
  7.     .hide {
  8.       visibility: hidden;
  9.     }
  10.   </style>
  11.   <script>
  12.     /*global window, document */
  13.     'use strict';
  14.     function Hide() {
  15.       this.setAttribute('class', 'hide');
  16.     }
  17.     window.addEventListener('load', function () {
  18.       var images, i, length;
  19.       images = document.querySelectorAll('img');
  20.       length = images.length;
  21.       for (i = 0; i !== length; i += 1) {
  22.         images[i].onclick = Hide;
  23.       }
  24.     });
  25.   </script>
  26. </head>
  27. <body>
  28.   <img src="http://s1.stc.m.kpcdn.net/share/i/3/1559845/middle.jpg" alt="Первый">
  29.   <img src="http://s13.stc.m.kpcdn.net/share/i/3/2708980/middle.jpg" alt="Второй">
  30.   <img src="http://s14.stc.m.kpcdn.net/share/i/3/2708972/middle.jpg" alt="Третий">
  31.   <img src="http://s14.stc.m.kpcdn.net/share/i/3/2708978/middle.jpg" alt="Четвёртый">
  32.   <img src="http://s13.stc.m.kpcdn.net/share/i/3/2708977/middle.jpg" alt="Пятый">
  33. </body>
  34. </html>
RAW Paste Data