Blade
Blade

Reputation: 51

Not all css working after prependTo or appendTo with Jquery

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

Answers (1)

Naftali
Naftali

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

Related Questions