Consider this runnable example: Why is el4 not put after el3? If I debug and print el3 it seems that el4 has disappeared. How can I put an element after another element, so that they become siblings?
EDIT: I don't want to append el3, before calling .after(). I simply have two angular.elements an I want combine them into two siblings, and the append or replace them in the directive element.
angular.module('myModule', [])
.directive('mydir', [function () {
return {
restrict: 'E',
scope: {},
template:'<div><b>{{myf.str}}</b>',
link: function (scope, elem, attrs, ctrl) {
var el = angular.element('<b>First </b>');
var el2 = angular.element('<i>Second</i><br>');
el.append(el2);
elem.append(el);
var el3 = angular.element('<b>Third </b>');
var el4 = angular.element('<i>Fourth</i>');
el3.after(el4);
elem.append(el3);
}
};
}])
<html ng-app='myModule'>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<mydir></mydir>