plugin jQuery file from local Pc into Html file - javascript

//the jQuery file and the location
<script src="C:/xampp/htdocs/AnasCourse/BootStarp/jQ.js"></script>
//i even tried this one
<script type="text/javascript" src="file:///C:/xampp/htdocs/AnasCourse/BootStarp/jQ.js"></script>
// Simple code in jQ.js file :
<script>
$(document).ready(function(){
$("p").hide();
})
</script>
//and the result from the Console is:
Uncaught ReferenceError: $ is not defined

<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
I think you not include the jQuery file first.

Related

Error in Success callbackId: GeolocationXXXX : ReferenceError: Can't find variable: $ [duplicate]

I am using jQuery. This is my coding on my main page:
<script type="text/javascript" src="script.js">
</script>
and my script.js is:
$(document).ready(function(){
$("#title").click(function () {
alert("Works!");
});
});
My full coding can be found here: http://pastie.org/8676656.
Using a tool on the browser, I found an error in my javascript code:
ReferenceError: Can't find variable: $
on line:
$(document).ready(function() {
Any help would be appreciated.
You have to import jQuery before using it:
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
Notice it is using // as protocol (not http:// or https://), it means: if your .html file is at a http:// server, it will get jQuery from http://ajax.google..., and if it is at a https:// server, it will get it from https://ajax.google....
Note: If, while developing, you open your HTML file in your browser instead of in a server, you should specify the protocol, as in this answer, otherwise it won't work:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
Also, you should, if possible, place your .js files at the bottom of the page, right before closing </body>. See more in here.
Import jQuery before your code
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"><script>
Include jQuery before your script
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js></script>
this is jquery load problem,
load jquery before all your code and script.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js" ></script>

kongregate not defined error javascript

I have included the required files in the head as it says in the docs
<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js'></script>
<script src='https://cdn1.kongregate.com/javascripts/kongregate_api.js'></script>
And then right above my scripts i included the script that supposed to define the variable
<script>
kongregateAPI.loadAPI(function(){
window.kongregate = kongregateAPI.getAPI();
});
</script>
But in the console I am still getting this error
Uncaught ReferenceError: kongregate is not defined
You said:
And then right above my scripts i included
Does it mean that your code looks like this?
<script>
kongregateAPI.loadAPI(function(){
window.kongregate = kongregateAPI.getAPI();
});
</script>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js'></script>
<script src='https://cdn1.kongregate.com/javascripts/kongregate_api.js'></script>
If so, you should call kongregateAPI functions after you loaded api js file:
<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js'></script>
<script src='https://cdn1.kongregate.com/javascripts/kongregate_api.js'></script>
<script>
kongregateAPI.loadAPI(function(){
window.kongregate = kongregateAPI.getAPI();
});
</script>
I've tried it, everything works fine.

Access a Function From Another File

I have two file:
html2canvas.js
function html2canvas(){
}
myid_print.js
(function ($) {
$(document).ready(function() {
//I want to call html2canvas function here
html2canvas();
});
})(jQuery);
I already included both files in my html but after running the code above, the console shows an error saying:
Uncaught ReferenceError: html2canvas is not defined
How will I call the function from inside my second file?
Try implementing your Client side code as :
<head>
....
<script src="html2canvas.js" type="text/javascript"></script>
<script src="myid_print.js" type="text/javascript"></script>
....
<head>
<body>
...
<script type="text/javascript">
function_from_myid_print();
</script>
...
</body>
Inside which you can call html2canvas();
This will surely help you.
For more details refer links:
https://stackoverflow.com/a/3809896/4763053 and https://stackoverflow.com/a/25963012/4763053
Try put your JS script at the bottom of your HTML page.

JQuery does not work: uncaught type error

I have placed the following JQuery script in my HTML site header just to test if it works:
//in the header
<script src="modules/mod_djmenu/assets/js/catimage.js" type="text/javascript"></script>
//This is inside the script, it does load according to Chrome Developer Tools
$(document).ready(function(){
$("#navbar").hide();
});
navbar does not hide and I get the error (in Chrome Developer Tools):
Uncaught TypeError: Object # has no method 'ready'
Have I placed the script in the wrong place? I use Joomla for my site btw.
Site: europebathroom.com
Thanks in advance!
Include Jquery Library in head section
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" type="text/javascript"></script>
<script src="modules/mod_djmenu/assets/js/catimage.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
$("#navbar").hide();
});
</script>
Seems like you havent include jquery in your code. Include the jquery, either by refering online or save it as local.
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="modules/mod_djmenu/assets/js/catimage.js" type="text/javascript"></script>
//This is inside the script, it does load according to Chrome Developer Tools
$(document).ready(function(){
$("#navbar").hide();
});
Add this below script. before your script as you need to add jquery script before it.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" type="text/javascript">

how to load jquery and other javascript file

This is my first time using lightbox which uses jquery framework. But when I paste jQuery and Lightbox javascript files into my html page, my current javascript code doesn't work properly. Is the way I set them up wrong? Thank you. This is the order I put my js files
the error I got is:
Uncaught TypeError: Object [object Object] has no method 'dispatchEvent' prototype.js:5734
Edit:
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js" type="text/javascript"></script>
<script src="random.js" type="text/javascript"></script>
<script src="js/jquery-1.7.2.min.js"></script>
<script src="load-poll.js" type="text/javascript"></script>
<script src="js/lightbox.js"></script>
And this is the beginning of my own js file as the page loads:
var POLL_WIDTH = 200;
document.observe("dom:loaded", function() {
if ($("favChar")){
fetchPoll("favChar");
}else if ($("favVoice")){
fetchPoll("favVoice");
}else if ($("CMTvote")){
fetchPoll("CMTvote");
}else if ($("BLdesign")){
fetchPoll("BLdesign");
}
});
Try using this
$(function() {
// your init code
});
instead of
document.observe("dom:loaded", function() {
// your init code
});

Categories

Resources