Your initial attempt is the usual way. It looks like this:
Not sure where you went wrong. Add some more information and screenshots of your HTML-snippet with the JS.
Tim van Steenbergen
Tim’s solution is easiest.
It is possible to create a setup where you can do this sort of stuff dynamically
For this you have to add some js that listens to page change, checks the page in the db, if it has a script ,execute it
I also have a thing where I can load in libs referenced by these page scripts, these are configured and served up via the rest service/request handler, so you can build/store libs and reference these on your page scripts