I am trying to add spans to a div via jquery. These spans should have an onclick event. The spans seem to be added, but the newly created elements' click events don't fire. I'm worthless at jQuery and am not sure what I'm missing. Any help is appreciated.
Here is some relevant code:
<script type='text/javascript'>
$(window).load(function(){
$('#Match .WordSpan').click(function() {
alert($(this).html());
$('#Match').append('<span>me too!</span><br/>').html();
$("span:last").addClass("WordSpan").html();
});
});
</script>
<input type="text" id="WordInput" />
<div id="Match">
<span class="WordSpan">click me!</span><br />
</div>
I have it in a fiddle here.
What I am hoping the code will do is, after clicking on the hard coded "click me" span, another span will be added below. When clicked, that span will add another, saecula saeculorum.
Where have I blown it?