1

How do I go about using DOMDocument's createElement to create a new Javascript object in a document?

The best I have achieved so far is:

$node = $doc->createElement("script");

However, this outputs:

<script></script>

What I am looking to output is:

<script type="text/javascript"></script>
1
  • Why? The type attribute is redundant Commented Oct 3, 2014 at 6:31

1 Answer 1

2

Use the ->setAttribute method after creating the node:

$node->setAttribute('type', 'text/javascript');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.