Chris
Chris

Reputation: 37

get Javascript to not appear as code on the page

I don't know much about this, just having recently started with JavaScript, so simple language would be greatly appreciated.

Whenever I insert JavaScript on a page, it appears in the preview as text on the page and when I update my site it also appears this way. How would I fix this?

Thank you in advance.

Upvotes: 1

Views: 280

Answers (3)

Timothy Lee Russell
Timothy Lee Russell

Reputation: 3748

You need to provide a sample of what you are doing for us to help you.

However, you might check that your script declaration looks something like this:

<script type="text/javascript">
<!-- //html comment hides script from really old browsers

  myVar = resultsFromAMethod();

//-->
</script>

Upvotes: 0

Moses
Moses

Reputation: 9173

There are two ways to inject JavaScript into a page.

Inline in either the head or body of your html page.

<script type="text/javascript">
    alert('this is inline javascript');
</script>

Or you can link to an external JavaScript file from the head of your html document.

<script type="text/javascript" src="path/to/script.js"></script>

Just remember: if the javascript is an external file, save it with the .js extension.

Upvotes: 3

RememberME
RememberME

Reputation: 2092

Do you have it within <script type="text/javascript"></script> tags?

Upvotes: 3

Related Questions