I want to place a dynamically created Html Span element wherever I click mouse. I thought to use coordinate obtained from click but it didn't work.
Html:
<div id = "test" style="background:#7FFFD4; width:1000px; margin:20px; height:20px; position: relative;">
Area For Test
</div>
Script
$(document).ready(function () {
$("#test").click(function (e) {
$('#test').append('<span id = "abc">' + 'sampleText' + '</span>');
var x = Math.round(e.pageX - posX) + "px";
var y = Math.round(e.pageY - posY)+ "px";
$('#abc').css({ 'position': 'absolute', 'top': x, 'left': y});
});
});
So Is there a nice way to position Span Element where i click.