I am creating a grid that allows to select x number of buttons with numbers, and when the user clicks on the button it shows the number that it represents, I show the code.
$(document).ready(()=>{
$('#item1').click(()=>{//Quisiera implementar esto en cada uno de los
//botones, solo este funciona.
$('#item1').toggleClass('active')
$('#item1').toggleClass('disabled')
})
$('.item').click(()=>{
$(this).toggleClass('active')
$(this).toggleClass('disabled') //Los toggleClass tampoco se ejecutan al darle click
let valor= $(this).attr('value')
console.log(valor) //retorna undefined
})
});
<?php
echo "
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>Testing</title>
<link rel='stylesheet' href='css/main.css'>
<!-- <script src='js/jquery.plugin.min.js'></script> -->
<script src='js/jquery.min.js'></script>
<script src='js/main.js'></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> </script>
</head>
<body>
<div id='grid'>
<table>
";
echo "<tr>";
for ($i=1; $i <=500; $i++) {
echo "
<td class='item active' id='item".$i."'>".str_pad($i, 3, "0", STR_PAD_LEFT)."</td>
";
if ($i%10==0 || $i==0) {
echo "</tr><tr>";
}
}
echo "
</table>
</div>
</body>
</html>
";
?>
It happens that I have to add this function to each of the buttons, but it does not seem like a correct solution, to create a code for each button. I am new programming and it is one of my first tasks as a programmer, some idea of how I can solve this?