We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Service Portal widget onload DOM manipulation

xiaix
Tera Guru

In a Service Portal Widget, how do I manipulate the DOM once the HTML template has rendered?   (onload)

Thanks!

5 REPLIES 5

Paul Kunze
Kilo Sage

Hi, an easy way that works is to utilize the ng-init directive. You can include a function there which will be executed once when the DOM and AngularJS are loaded.

Here is an example:

<div id="container" ng-init="myFunction()">
</div>

You can write something like this in the Client Script:

api.controller=function($scope) {
	$scope.myFunction = function() {
		console.log('DOM has loaded');
	}
}