I like to create jquery elements in variables and place them where needed.
var $someElement = $("<span class='someclass'>something</span>").css("cursor", "pointer");
$("body").append($someElement)
for now everything is working. But if i try to bind a event to this element, the event does not get triggered:
var $someElement = $("<span class='someclass'>something</span>").css("cursor", "pointer").click(function(){ alert("yeah") });
$("body").append($someElement)
but if i append the element and the find the span by its class it works.
Why is this and how should i handle events on elements that are created but not yet apended?
<span>and closing with a</div>.