Just getting started with JS so I got a question.
What I would like to accomplish is for me to append a h1
tag inside a div
then click on it and trigger an alert.
<div id="heading">h1</div>
<div id="canvas"> </div>
<script>
$('#heading').on('click', function(e) {
$('#canvas').append('<h1>test</h1>');
});
$('#heading h1').on('click', function(e) {
alert('foo');
});
</script>
this is the code I have now. Now the issue as far as I understand is that the javascript code is ran on load - so when the h1
is added it won't work.
How do you fix this?