Reputation: 51
While creating a Div dynamically then using prependTo or appendTo to another div not all the css works. For instance, if:
var myDiv = $("<div></div>");
myDiv.attr("id", "xd_1").removeAttr('class').attr('class','boogar');
myDiv.css({'color': 'blue', 'height': '10px', 'width': '10px', 'top': '131px',
'left': '126px'}).html('52').prependTo("#numbers");
Only the css color, height and width works. top and left do not. Any ideas why this would be?
Upvotes: 0
Views: 210
Reputation: 146310
top
and left
do not do anything if the position is not relative, absolute or fixed.
Also try to change your code a bit (this is a mockup of what you can do):
var myDiv = $("<div>");
myDiv.prop("id", "xd_1")
.addClass('boogar')
.css({
'color': 'blue',
'height': '10px',
'width': '10px',
'top': '131px',
'left': '126px'})
.html('52').prependTo("#numbers");
Upvotes: 1