I'm trying to create an element on the fly and then get the center of said element. Here is what I have:
function drawnode(entity, x, y) {
var ele = ""
ele += "<div class='relNode'>";
ele += "<span>" + entity.name() + "</span>"
ele += "<div>"
var node = $(ele).appendTo('#rPaper').get(0);
var offset = node.offset();
var width = node.width();
var height = node.height();
var centerX = offset.left + width / 2;
var centerY = offset.top + height / 2;
node.css("top", centerY + y).css("left", centerX + x);
}
This gives the error
Object #<HTMLDivElement> has no method 'offset'
I originally tried it without the .get(0)
and it gives no errors but the height and width are both 0.
What am I doing wrong?