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".
Related
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>
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
When I get on one of my pages I want an lightbox to be loaded. I cant figure out how to make it happen.
Part of the jQuery:
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="jss/jquery.js"></script>
<script src='http://fliphtml5.com/plugin/LightBox/js/fliphtml5-light-box-api-min.js'></script>
<script>
$(document).ready(function() {
$(".foo").trigger('click');
});
</script>
</head>
The image/link that should be clicked automaticly:
<img class="foo" src="imgs/logo-growpact.png"data-rel='fh5-light-box-demo' data-href='http://online.fliphtml5.com/classified' data-width='1280' data-height='720' data-title='Rootcage'>
First Just remove your
<script type="text/javascript" src="jss/jquery.js"></script>
And try this :
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src='http://fliphtml5.com/plugin/LightBox/js/fliphtml5-light-box-api-min.js'></script>
</head>
<body>
<script>
jQuery(function(){
jQuery('.foo').click();
});
</script>
<img class="foo" src="imgs/logo-growpact.png" data-rel='fh5-light-box-demo' data-href='http://online.fliphtml5.com/classified' data-width='1280' data-height='720' data-title='Rootcage'>
</body>
</html>
Here is the Fiddle: CHECK THIS
UPDATED
<script>
jQuery(function(){
setTimeout(function(){
jQuery('.foo').click();
},400);
});
</script>
FIDDLE
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>.)
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
EDIT Here is new code but it is still not working for me.
HTML:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="mycss.css">
<script src="myjavascript2.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<button onclick="myFunction()">Play</button>
<p id="test"></p>
</body>
</html>
Javascript:
var things = ['rock','paper','scissors'];
function myFunction() {
var i = Math.floor(Math.random()*things.length));
document.getElementById("test"+(i+1)).innerHTML=things[i];
}
I added this text so that it would let me post the edit, please ignore this.
You could simply replace your whole code with
var things = ['rock','paper','scissors'];
var i = Math.floor((Math.random()*things.length));
document.getElementById("test").innerHTML=things[i];
This would also let you more easily deal with other operations, like finding a winner.
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
I am newbie of JavaScript and studying with textbook. I wrote below code, and alert modal window was displayed correctly, but document.writeln(triangle(8,5)) does nothing. Why?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Area of Triangle</title>
</head>
<body>
<h1>Area of Triangle</h1>
<pre>
<script type="text/javascript" charset="utf-8">
<!--
var triangle;
triangle = function(base, height) {
return base * height / 2;
};
alert(triangle(8, 5));
documnt.writeln(triangle(8, 5));
-->
</script>
</pre>
</body>
</html>
Thank you for your kindness.
You've misspelled document as documnt. Try:
document.writeln(triangle(8, 5));