So, i want to know how if i append something to a div, where in this append i give a id to the element "a", i can get that id.
JS
$(document).ready(function () {
console.log("ready!");
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: 'http://192.168.160.58/Formula1/api/Statistics/Champions',
dataType: "json",
success: function (data) {
for (var i = 0; i < data.length; i++) {
var k = data.length - i - 1;
if (i % 2 == 0) {
$(".timeline").append("<div class='container left'><div class='content'><center><h2><a id='" + data[k].Year + "' href='http://localhost:65418/StatisticsIntro.html'>" + data[k].Year + "</a></h2></center><center><img style='heigth:150px; width: 70px;' src ='" + data[k].ImageUrl + "' alt='" + data[k].DriverName + "'></img></center></div></div>");
} else
if (i % 2 != 0) {
$(".timeline").append("<div class='container right'><div class='content'><center><h2><a id='" + data[k].Year + "' href='http://localhost:65418/StatisticsIntro.html'>" + data[k].Year + "</a></h2></center><center><img style='heigth:200px; width: 70px;' src ='" + data[k].ImageUrl + "' alt='" + data[k].DriverName + "'></img></center></div>");
}
}
}
})
$("a").click(function () {
var myId = event.target.id;
sessionStorage.setItem("myId", myId);
})
})
HTML
<div class="timeline"></div>
<script src="../Scripts/bootstrap.min.js"></script>
<script src="../Scripts/jquery-3.6.0.js"></script>
<script src="Timeline.js"></script>
When i imprime event.target.id i get null.