-1

I have created an html file

<html>

<head>
  <title>test</title>
</head>

<body>
  <p id="demo">l</p>
  <script type="text/javascript" src="profile/test.js">
    s(shiva);
  </script>
</body>

</html>

i want to change the value of the paragaraph. So my external js file is

function s(nam) {
  document.getElementById("demo").innerHTML = nam;
}

But is not changing can anyone suggest me how can change the value.

1

1 Answer 1

0

You can not include code in a javascript tag with a "src" attribute. So move the loose javascript in a new tag.

<script type="text/javascript" src="profile/test.js"></script>

<script type="text/javascript">
    s('shiva');
</script>
Sign up to request clarification or add additional context in comments.

2 Comments

I changed but the paragraph value haven't changed
You need to put text inside quotes '' or "" like 'shiva' or "shiva". Do you have your inspection tool from your browser open? That would tell you about errors like "Uncaught ReferenceError: shiva is not defined"

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.