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 );
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')
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.
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>
Maybe a lighter weight approach would be:
angular.element(document.body).append(myElement);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With