My goal is to add a textarea to a sidebar on the right whenever a click is made on the page. The current code I have is as follows:
$('#page_to_be_clicked').click(function(e){
var offset = $(this).offset();
var comment_box_y_coord = e.pageY - offset.top;
alert(comment_box_y_coord);
$("#sidebar").append('<textarea id="cmmnt" rows="4" cols="10" '+
'style="position:absolute;top:'+comment_box_y_coord +
'px;left:5px"></textarea>');
})
The issue with this code is that if a textarea already exists at the specific location, a new textarea will be created on top of it. Ideally, I would like the textareas to be created one below the other when multiple clicks are made at the same point on the page.
Is there a way to check if a child already exists at the required coordinates before creating a new one?
Any assistance on this matter would be greatly appreciated. Thank you.
How should the textareas appear when clicked in a sequence: