Reputation: 444
I'm trying to append html to after the first h1 on the page. angular.element is return the h1 element but it's not appending the text "hello!" after the h1 element.Trying to avoid using full JQuery. Anyone with ideas?
app.controller('Test', ['$scope', function ($scope) {
var h1 = angular.element(document).find("h1").length > 0 ? angular.element(document).find("h1")[0] : null
if (h1 != null) {
angular.element(h1).after(function () {
return "hello!"
})
}
}]);
Upvotes: 0
Views: 401
Reputation: 1609
Change angular.element(h1)
to $(h1)
.
$(h1).after(function () {
return "hello!"
})
http://jsfiddle.net/ms403Ly8/94/
Upvotes: 1
Reputation: 194
Do not pass a function in after
, just include your desired text as the parameter.
if (h1 != null) {
angular.element(h1).after('Hello')
}
Upvotes: 1