<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("button").click(function() {
$("h2").html("<p class='test'>click me</p>")
});
$(".test").click(function(){
alert();
});
});
</script>
</head>
<body>
<h2></h2>
<button>generate new element</button>
</body>
</html>
I was trying to generate a new tag with class name test
in the <h2>
by clicking the button. I also defined a click event associated with test
. But the event doesn't work.
Can anyone help?
inside
in valid HTML
– Josef Engelfrost Apr 30 '14 at 09:15