Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS implement element's before method without jQuery

Is there a simple way to implement before method for DOM manipulation without jQuery in my AngularJS directive?

jQuery way is:

$element.before($insertedBeforeElement);
like image 713
Artem Platonov Avatar asked Dec 19 '22 18:12

Artem Platonov


2 Answers

To do it without jQuery but with angular's jqLite:

$element.parent()[0].insertBefore($insertedBeforeElement[0], $element[0]);
like image 177
Artem Platonov Avatar answered Dec 30 '22 17:12

Artem Platonov


jqLite does support .after() so you can use that to do a little shuffling.

$element.after($insertedBeforeElement); //add it after
$insertedBeforeElement.after($element); //now switch the positions
like image 27
FiniteLooper Avatar answered Dec 30 '22 19:12

FiniteLooper