Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can create and append an element to document body? (angular)

Tags:

In a directive i want to create a div and append it to the document. what am i doing wrong?

var mover = angular.element('<div></div>');      mover.css({       position: 'absolute',       top: '0px',       bottom: '0px',       left: '33px',       width: '50px',       background: 'blue',       zIndex: '2'     });      $document.append( mover ); 
like image 409
Ivan Bacher Avatar asked Mar 12 '14 10:03

Ivan Bacher


People also ask

How to append HTML element?

HTML code can be appended to a div using the insertAdjacentHTML() method. However, you need to select an element inside the div to add the code. This method takes two parameters: The position (in the document) where you want to insert the code ('afterbegin', 'beforebegin', 'afterend', 'beforeend')

What is Document body append?

The Document. append() method inserts a set of Node objects or string objects after the last child of the document. String objects are inserted as equivalent Text nodes. This method appends a child to a Document . To append to an arbitrary element in the tree, see Element.

What is append to body?

append() is a method that adds (an) additional element(s) to the end of the selected parent element. $('body').append('<div>Appended to BODY</div>'); Before: <body> </body> After: <body> <div>Appended to BODY</div> </body>


1 Answers

Maybe a lighter weight approach would be:

angular.element(document.body).append(myElement); 
like image 92
Fabio Nolasco Avatar answered Sep 28 '22 08:09

Fabio Nolasco