Will Noel
Will Noel

Reputation: 69

Why does Dreamweaver show syntax error for this script line?

Why does Dreamweaver page using .dwt show syntax error for this script line?

<script>
    window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>');
</script>

It shows syntax error only on a page using the template .dwt file. Does not show error in the template - only when applied to a page.

Upvotes: 1

Views: 1035

Answers (1)

user4639281
user4639281

Reputation:

You are not escaping the first / character

<script>
    window.jQuery || document.write('<script src="js/jquery.min.js"> <\/script>');
</script>

Should be

<script>
    window.jQuery || document.write('<script src="js\/jquery.min.js"> <\/script>');
</script>

Although you can use document.createElement('script') which is less confusing for the parser

if(!window.jQuery) {
    var script = document.createElement("script");
    script.src = "js/jquery.min.js";
    document.body.appendChild(script);
}

Upvotes: 1

Related Questions