I am teaching myself how to program usign JS, jQuery, HTML and CSS. I downloaded the jquery-master from github and use it in my project, however I still cannot get it to import into my HTML files so that I can utilize it. Does anybody know how? Any help would be appreciated!
you can use this js file you donot need to download js files you just need to place this script tag to each html page where you are trying to play with jquery code.
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
use this script and include your jquery code inside this script block
<script type="text/javascript"> alert('hi friend') </script>
hope this will works Thanks.
Related
Is it possible to copy and paste a javascript library's code inside a HTML file?
I asked because I'm trying to make an app that needs angularjs but due to restrictions at work, I cant reference it to an angularjs file externally regardless if its over the internet or intranet.
I appreciate your help.
Thanks
Yes this is possible but very much not recommended.
This can be done the following way using the <script> tag:
<body>
<p>This is HTML bla bla bla...</p>
</body>
<script type="text/javascript">
//Put your JS code here
</script>
I am using a simple plugin from http://www.highcharts.com/demo/pie-basic which has a javascript file stored in view options. I am using this file in my index.html code as <script src="js/pie1.js"></script> inside <body> tag where pie1 is a javascript file stored in js folder. When i run my html page nothing happens.
can anyone help me where I am getting wrong? I am new to using plugins so please bear with me and correct me if anything is wrong.
Most likely you have this situation because javascript start running the plugin before your html is ready.
Place <script src="js/pie1.js"></script> just before closing tag </body>
I'm totally new at coding and i have some trouble using the dragNodes plugin. I can make the plugin work by itself with the generated random graph example, but I am struggling to make it work with my own graph.
I don't understand what to put in the html. I tried to put only that:
`<script src="sigma.js/plugins/sigma.plugins.dragNodes/sigma.plugins.dragNodes.js"></script>sigma.plugins.dragNodes(s, s.renderers[0]);`
and it doesn't make my nodes move. I think I have to change the content of "s" and "s.renderers[0]" but I cannot find where., and I don't know how to do it...
Basically, I would love if anyone could give me some explanations about how to plug a plugin in my page?
If you could help me, I'm lost and that would be awesome! Thank you a lot!
I think you are mixing up two things:
How to use script into html
How to include external js files in a web page.
In order to insert javascript directly into an html page you have to use the script tag as follow (called inline js):
<body>
<script>
// some inline js
var a = 1;
</script>
</body>
In order to include js from an external file you have to reference the file with the src attribute just like you did.
<script src="sigma.js/plugins/sigma.plugins.dragNodes/sigma.plugins.dragNodes.js"></script>
The only thing that you missed is that sigma.plugins.dragNodes(s, s.renderers[0]); is also some js code, you thus have to put it into script tags to that it can be interpreted as such by the browser.
Here is what you probably are trying to write:
<script src="sigma.js/plugins/sigma.plugins.dragNodes/sigma.plugins.dragNodes.js">
</script>
<script>
sigma.plugins.dragNodes(s, s.renderers[0]);
</script>
Having all this into <body>tags.
I should also mention that to render your graph using sigma you should have an instance of sigma in your page, and in your case it should be called s.
To learn more about js/web programming I would advise this: http://www.codecademy.com/
As far as documentation for sigma is concerned check out their tutorial: http://sigmajs.org/
In addition to Nicolas Joseph's answer (put javascript in script tag), you should also download the js library that is required and save the html file in the appropriate path.
For example if your file.html is in a directory dir (dir/file/.html)
Then the command:
<script src="sigma.js/plugins/sigma.plugins.dragNodes/sigma.plugins.dragNodes.js">
</script>
will search for a file named sigma.plugins.dragNodes.js in the following path:
dir/sigma.js/plugins/sigma.plugins.dragNodes/sigma.plugins.dragNodes.js
To check out which librarires you are missing you should open debug mode in your browser (right click->inspect element) and check the console tab.
Cheers
I'm following a tutorial for vendoring jQuery in a Sinatra app and I can't seem to get jQuery to function. I usually use Google's CDN to load jQuery and it works every time but I can't seem to load it by vendoring and I don't know why. I'm more than certain this is something very trivial but I don't see it. Here are the directions I've followed as suggested by my tutorial.
Create a public/vendor/jquery.js file
Copy and paste the the UNCOMPRESSED jquery 1.11 into jquery.js
Create a javascripts/rating.js file and include this code to verify if jquery loaded.
$(function(){
console.log("loaded...");
});
When I use the inspect element tool and click on the Network tab, it says that jquery can't be found. What's going on? Oh and this is my index.html.erb file:
<body>
<h1>Rate It</h1>
<div id="rating-container"></div>
<script src="public/vendor/jquery.js" type="text/javascript"></script>
<script src="javascripts/rating.js" type="text/javascript"></script>
</body>
Help would be greatly appreciated. Thanks guys.
I finally got it. The tutorial has a typo in it! Referencing vendor/jquery.js instead of public/vendor/jquery.js worked. Geez.
I don't know much about this, just having recently started with JavaScript, so simple language would be greatly appreciated.
Whenever I insert JavaScript on a page, it appears in the preview as text on the page and when I update my site it also appears this way. How would I fix this?
Thank you in advance.
There are two ways to inject JavaScript into a page.
Inline in either the head or body of your html page.
<script type="text/javascript">
alert('this is inline javascript');
</script>
Or you can link to an external JavaScript file from the head of your html document.
<script type="text/javascript" src="path/to/script.js"></script>
Just remember: if the javascript is an external file, save it with the .js extension.
Do you have it within <script type="text/javascript"></script> tags?
You need to provide a sample of what you are doing for us to help you.
However, you might check that your script declaration looks something like this:
<script type="text/javascript">
<!-- //html comment hides script from really old browsers
myVar = resultsFromAMethod();
//-->
</script>