Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
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.
Improve this question
I have a problem with using an external *.js file in a *.html file.
What I want to achieve is to modify a div. No matter what I do I can't seem to make it working. Why isn't this working ?
document.getElementById("MyDiv").color = "red";
x.color = "blue";
MyDiv.color = "red";
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="JavaScript.js"></script>
<title>js</title>
</head>
<body>
<div id="MyDiv">12</div>
</body>
</html>
,
Try
document.getElementById("MyDiv").style.color = "red";
after the document loaded. Usage of jQuery would be helpful. With jQuery:
$(document).ready(function() {
document.getElementById("MyDiv").style.color = "red";
}
Or native: Put the script tag at the end of your body tag:
<script>
(function() {
document.getElementById("MyDiv").style.color = "red";
})();
</script>
Why cant you just include the Script in the <head>? If it is only that small piece then it should be no Problem.
If you are linking to an external file, be sure the link path is correct.
Code below will resolve your problem:
var MyDiv = document.getElementById("MyDiv");
MyDiv.style.color = "red";
MyDiv.innerHTML = "asdkjnasd";
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>js</title>
</head>
<body>
<div id="MyDiv">12</div>
</body>
</html>
Related
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 know I'm a beginner at this, but I really need to learn the rules. I'm trying to make a simple example of javascript. Its a box with three buttons, but for some reason only one of them works. They do have different ID types, so there must be another rule I don't know.
<!DOCTYPE html>
<html>
<head>
<title>Javascript box</title>
</head>
<body>
<p>Press buttons to change the box</p>
<div id="box" style="height:100px; width:100px; background-color: limegreen; margin:50px"></div>
<br>
<button id="less">less</button>
<button id="more">more</button>
<button id="none">Reset</button>
<script type="text/javascript">
document.getElementById("less").addEventListener("click", function(){
document.getElementById("box").style.height = "25px";
});
document.getElementByID("more").addEventListener("click", function(){
document.getElementById("box").style.height = "150px";
});
document.getElementById("none").addEventListener("click", function(){
document.getElementById("box").style.height = "100px";
});
</script>
</body>
</html>
For the second addEventListener, there's a typo.
In document.getElementByID, the D should not be capitalised.
A good way to debug these issues is to look at the console in developer tools.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
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.
Improve this question
Hello,
I downloaded electron and installed it on webstorm in order to learn it. I also installed Jquery using the terminal and including in my scripts but jquery isn't working but it is recognized in my code (I haven't got any error).
My code :
const remote = require('electron').remote;
let window = remote.getCurrentWindow();
function exitGame() {
alert("test");
$('exit').click(() => {
alert("closing");
window.close();
})
}
exitGame();
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Electron Test</title>
<!-- RESET CSS -->
<link rel="stylesheet" type="text/css" href="css/reset.css">
<!-- ADDING CSS -->
<link rel="stylesheet" type="text/css" href="css/main_menu.css">
</head>
<body>
<div id="exit">Leave the game</div>
<!-- ADDING JAVASCRIPT -->
<script>
// You can also require other files to run in this process
require('./renderer.js');
require('./js/jquery.min.js');
require('./js/main_menu.js');
</script>
</body>
</html>
The jQuery alert is working but the click isn't.
Even if I replace the "exit" id by "body" it's not working...
Can you tell me what's wrong ?
Thank you very much, best regards.
exit is an id and not some element. So you need to use # before it.
$('#exit').click(() => {
alert("closing");
window.close();
})
Better way to check jQuer is wokring or not could be:
if(!jQuery)
{
alert("Not working!");
}
Alright, made it working by editing the tag with the code requiere jQuery.
Before Electron's base script tag, I added a tag with my jQuery. It seems that it wasn't loaded
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 7 years ago.
Improve this question
Receiving the following error in developer console when loading the page:
Uncaught ReferenceError: toastr is not defined
Here are the html contents. Can someone please explain to me why toastr is undefined?
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css">
</head>
<body>
<p>Toastr TEST</p>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
<script scr="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.0.2/js/toastr.min.js">
</script>
<script>
$(document).ready(function() {
console.log("document.ready");
toastr.info('document.ready');
});
$(window).load(function() {
console.log("window.load");
toastr.info('window.load');
});
</script>
</body>
</html>
You have the script elemen's src attribute wrongly spelled for the toaster.js file, it should be "src" but is "scr".
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Well here's my Function as well as my basic HTML page. I have created it with an alert script but it does not run.
Here's the function (Something.js)
function crypto_encrypt(text) { //This is for JS
var keyBase64 = CryptoJS.enc.Base64.parse("ITU2NjNhI0tOc2FmZExOTQ==");
var iv = CryptoJS.enc.Base64.parse('AAAAAAAAAAAAAAAAAAAAAA==');
var encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(text), keyBase64,
{
keySize: 128 / 8,
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
// Returns a Base64 encoded string.
return encrypted;
}
Now I have this HTML but when i load it it does not give an alert
(Test.php) <-----does it have something to do with the naming when I saved it in sublime?
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type='text/javascript' src='./jquery.soap.js'></script>
<!--<script type='text/javascript' src='./soapclient.js'></script>-->
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"> </script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc- base64-min.js"></script>
<script type='text/javascript' src='./HCSConnect.js'></script>
</head>
<body>
<script language="JavaScript">
var encryptedname = crypto_encrypt('Patrick');
alert(encryptedname)
</script>
</body>
</html>
There are some spaces in the url for this script:
http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc- base64-min.js
That is the reason you get a 404 (not found). The entire following script fails. Change it to:
http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js
See this jsfiddle.
You are missing a ; after alert() statement.
Remove spaces from source URL:
<script type="text/javascript" src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"
Also, it is advisable to use type="text/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 8 years ago.
Improve this question
My html is like this:
<!DOCTYPE html>
<html>
<head>
<title>
Event Handling
</title>
</head>
<body>
<h1> This is the chapter in which I am handling Events.The site you should visit is: </h1>
<b>here<b>
<script src="events.js"></src>
</body>
</html>
The javascript is like this:
var link = document.getElementsByTagName("a")[0];
link.onclick = MyEventHandler;
function MyEventHandler()
{
alert("ouch!");
return false;
}
It is not working, but using inling event handler I am doing it successfully. Please helop me.
You need to assign the event handler function, not the return value of calling that function.
link.onclick = MyEventHandler;
(Also note that you need to use the end tag </script> not </src>.)