TheDeanVanGreunen

example.html

Sep 1st, 2019
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.42 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7.     <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
  8.     <title>Example 1</title>
  9. </head>
  10. <body>
  11.     <div>
  12.         <img src="https://cdn2.iconfinder.com/data/icons/job-industrial/32/expand-ckstudio-basic-solid-32px_basic_general_universal_job_calendar-512.png"  style="width:32px; height:32px;" alt="" id="img0" name="img0"><br>
  13.         <img src="https://cdn2.iconfinder.com/data/icons/job-industrial/32/expand-ckstudio-basic-solid-32px_basic_general_universal_job_calendar-512.png"  style="width:32px; height:32px;" alt="" id="img1" name="img1"><br>
  14.         <img src="https://cdn2.iconfinder.com/data/icons/job-industrial/32/expand-ckstudio-basic-solid-32px_basic_general_universal_job_calendar-512.png"  style="width:32px; height:32px;" alt="" id="img2" name="img2"><br>
  15.         <img src="https://cdn2.iconfinder.com/data/icons/job-industrial/32/expand-ckstudio-basic-solid-32px_basic_general_universal_job_calendar-512.png"  style="width:32px; height:32px;" alt="" id="img3" name="img3"><br>
  16.         <img src="https://cdn2.iconfinder.com/data/icons/job-industrial/32/expand-ckstudio-basic-solid-32px_basic_general_universal_job_calendar-512.png"  style="width:32px; height:32px;" alt="" id="img4" name="img4"><br>
  17.         <img src="https://cdn2.iconfinder.com/data/icons/job-industrial/32/expand-ckstudio-basic-solid-32px_basic_general_universal_job_calendar-512.png"  style="width:32px; height:32px;" alt="" id="img5" name="img5"><br>
  18.     </div>
  19.     <script>
  20.         // Global Variable
  21.         let status = -1;
  22.         let imgs = [
  23.             $('#img0'),
  24.             $('#img1'),
  25.             $('#img2'),
  26.             $('#img3'),
  27.             $('#img4'),
  28.             $('#img5'),
  29.         ]
  30.  
  31.         // Functions
  32.         function imgClick(elm){
  33.             status = imgs.indexOf(elm); // This will set the status variable to the element index, using indexOf function. it will check inside of imgs variable which element index it is, if it cant be found status will return a -1  value
  34.         }
  35.  
  36.         // Execute
  37.         imgs.forEach(img => img.on('click', () => {
  38.             imgClick(img); 
  39.         }));
  40.     </script>
  41. </body>
  42. </html>
Add Comment
Please, Sign In to add comment