I use event.target.id
several times on a page, but in one particular case it just doesn't work. It seems to return either null
or an empty string.
$(document).ready(function() {
var $modal = $('body');
var $imgID = 'idcodeoftheimage';
var $after2 = '<div class="w3-bar w3-bottom w3-center buttonbar"><div class="buttons"><a href="javascript:;" id="' + $imgID + '" class="flag"><i class="">Flag</i></a></div></div>';
$modal.append($after2);
$('body').on('click', '.flag', function(event) {
var $id = event.target.id;
console.log($id);
});
});
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
</body>
</html>
The exact same line of code works elsewhere so I'm not sure what the issue is.