In the example below, the loaded script will appear in the 'head' with a plain 'script' tag but how do I add an id into the declaration so the result is something like 'script id="my-script"'

    window.event("domready", function() {
        alert("An inline JavaScript Declaration");

1 Answer 1


JDocument has a method for inserting arbitrary characters into the head tag. People usually use it for meta tags etc. It's down the bottom of this page:


$document = JFactory::getDocument();
$document->addCustomTag( '<script id="my-script">window.event("domready", function() { alert("An inline JavaScript Declaration"); });</script>' );
  • Ahhh, thank you. I'll give this a try. Cheers. Oct 2, 2017 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.