<script scr='..'> isnt connecting with file [closed] - javascript

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I'm trying to connect a JS script to my file but non of the files are working.
Main file is called menunew.html
JS file is in a folder called JS/menunew.js
I tried to include type=".."
I tried to place it in the head and body.
I tried using /JS/menunew.js
I tried using other files in the /JS/ map.
<!DOCTYPE html>
<html lang="en">
<head>
<title>New menu</title>
<link rel="stylesheet" href="CSS/menunew.css">
<script scr="/JS/menunew.js"></script>
</head>
I except them to connect.

Googling it would have been faster !
inside your body, just add :
<script type="text/javascript" src="yourScript.js"></script>

Related

Html file not reading .js? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
This question has been asked ~10^4 times, but hear me out that I've done my due dilligence in reading the solutions and seeing if their tweaks fix things (to no avail). I'm an amateur when it comes to JS/CSS/HTML but I'm learning. I am trying to implement this sticky navigation bar from here (also see here). My question isn't about their code, which appears to be fine.
When I implement it, my .html file doesn't seem to be using the .js script at all. None of the buttons respond, I don't get any errors, but everything in the .css and .html files otherwise are rendering fine. The head:
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<script type="text/javascript" src="script.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</head>
...
</html>
The script.js should be in the correctly referenced directory.
Answer (as I was writing this): The jquery script and the custom script were in the wrong order. :)

javascript code linked in an HTML file does not work in chrome console [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have a javascript code in separate file linked with an html file . When I run that html file on chrome,the console does not respond to that linked javascript file.
Here is the html code:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script type="myscript.js">
</script>
</head>
<body>
</body>
</html>
And this is the javascript code:
var x = 0;
while (x<5) {
console.log('x is currenlty: '+5);
console.log('adding 1 to x');
x = x +1;
}
I expect the console to respond to print out the console log but on chrome nothing happens.
Can someone help me?
You are using "type" instead of "src" on script tag.
<script src='myscript.js'></script>
If you change this on your code, it will work fine.

External Javascript not working, it is greyed out by Atom. They are in the same folder, is it just Atom or am I just stupid? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
External Js not working, greyed out by Atom
Not-working: The button is not showing on the site and the script is greyed out so it is not active as if it was a comment.
The html code is:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>JavaScriptGyak3</title>
<script type="text/javascript" src="page3.js" </script>
</head>
<body id="test">
<button type="button" onclick="hatszin()"> Change Background </button>
</body>
</html>
The js code is just:
function hatszin() {
document.getElementById('test').style.backgroundColor = 'orange';
}
You need to close the opening <script> tag properly by adding a >
<script type="text/javascript" src="page3.js"> </script>
^
Found a solution, had to give the body context (I placed a h1 in there) and now everything looks like shows like as it should.

Problems With Linking JavaScript with Html [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
Here is my html linking the .js file
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="CSS/Style.css">
<title>
Learning JavaScript
</title>
</head>
<body>
<div class="LargeTitle">
<h1>Learning JavaScript</h1>
<p class="UnderText">asap</p>
</div>
</body>
<script scr="Scripts/MainJavaScript.js"></script>
</html>
and here is a picture of the file locations
File Location = http://imgur.com/yCpEzbN
and here is the script:
alert("Is it working?");
Hopefully someone can help me with this
You have a typo, change <script scr="Scripts/MainJavaScript.js"></script> to <script src="Scripts/MainJavaScript.js"></script>
The attribute for script should be src instead of scr
Also, put the script tag inside the body tag or the head tag

Have I linked up this HTML and JavaScript file correctly? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
This is a small exercise in W3Schools that I wanted to try in my browser. The toggle animation did not work when I set the files separately, but it worked when I put the script within the HTML. Am I linking up the files wrong when they are separate? I also tried placing the script between the <head> tags, and that didn't work either.
HTML:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"type="text/css"href="main.css"/>
</head>
<body>
<div class="container" onclick="myFunction(x)">
<div class="bar1"></div>
<div class="bar2"></div>
<div class="bar3"></div>
</div>
<script type="text/javascript"src="script.js"></script>
</body>
</html>
JS:
function myFunction(x){
x.classList.toggle("change")
}
Thank you!
The tag
<script type="text/javascript"src="script.js"></script>
should suffice IF you saved the Javascript file as "script.js" in the same folder as your HTML file.
Also notice that the following line doesn't have a context for x:
<div class="container" onclick="myFunction(x)">
Maybe you are trying to do something like:
<div class="container" onclick="myFunction(this)">

Categories

Resources