-
Notifications
You must be signed in to change notification settings - Fork 0
/
increment.php
36 lines (32 loc) · 915 Bytes
/
increment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Div Click Event</title>
</head>
<body>
<?php
// PHP code to generate div elements with unique IDs
for ($i = 1; $i <= 5; $i++) {
?>
<div id='up<?php echo $i;?>' class='clickable'>up<?php echo $i;?></div>
<div id='down<?php echo $i;?>' class='clickable'>down<?php echo $i;?></div>
<?php
}
?>
<script>
// JavaScript code to attach click event listener to each div
document.addEventListener('DOMContentLoaded', function() {
// Get all div elements with class 'clickable'
var divs = document.querySelectorAll('.clickable');
// Attach click event listener to each div
divs.forEach(function(div) {
div.addEventListener('click', function() {
console.log('Div clicked:', this.id);
});
});
});
</script>
</body>
</html>