Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
- <title>Example 1</title>
- </head>
- <body>
- <div>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- </div>
- <script>
- // Global Variable
- let status = -1;
- let imgs = [
- $('#img0'),
- $('#img1'),
- $('#img2'),
- $('#img3'),
- $('#img4'),
- $('#img5'),
- ]
- // Functions
- function imgClick(elm){
- 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
- }
- // Execute
- imgs.forEach(img => img.on('click', () => {
- imgClick(img);
- }));
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment