April 7, 2015
Javascript is dynamic programming language that most common web browsers can interpret. It is most often used to create dynamic web interfaces, but can also be used for server-side programming, or to develop desktop and mobile applications. Check out the Javascript Wikipedia entry for more details on its history, implementations and usage.
jQuery's Javascript 101 and W3School's Javascript Tutorial provide a good introductions to Javascript as well.
We can include Javascript in our pages in three ways:
To include external Javascript files or embed Javascript locally, we use the script tag:
<script>
...
</script>
When using the script tag to include external javascript files, we use the src attribute to include to path to our Javascript file.
<script src="/path/to/my/javascript_file.js"></script>
When embedding our Javascript locally, we simply write our javascript between the <script> tag and the </script> tag.
<script>
/* here's my Javascript */
var myVariable = 0;
console.log(myVariable);
</script>
When using inline Javascript, you attach the javascript as an attribute to your target HTML element:
<a href="javascript:alert( 'Hello World' );">Click Me!</a>
Type examples in jQuery documentation
Operator examples in jQuery documentation
Conditional examples in jQuery documentation
Loop examples in jQuery documentation
Create a simple HTML page and add Javascript using the three methods above:
alert("My first linked Javascript!");
<script src="/path/to/my/javascript_file.js"></script>
tagalert("My first embedded Javascript!");
between them<a href=""></a>
and include the line javascript:alert("My first inline Javascript!");
inside the href attributejQuery is a Cross-Browser Javascript library that is designed to simplify using Javascript for common tasks including user interface enhancements, special effects, managing events, handling forms and more. For more information on jQuery and its background, checkout the jQuery Wikipedia entry.
To include jQuery in your project, you can either download it and link it in as you would your other Javascript files, or you can use jQuery's CDN:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
$( document ).ready() documentation
Selecting Elements with jQuery
jQuery Plugins are extensions to jQuery written and packaged by third party developers that provide some specific feature not covered by jQuery Core. If you're looking for a photo gallery feature, a parallax feature or many, many others, chances are, someone has made a jQuery Plugin for it.
You can find plugins in the jQuery Plugin Registry. They're organized by tag, so you can explore them based on the funtionality you're looking for.
Every plugin has it's own installation requirements, but generally speak, you'll only need to link in the plugin's javascript file and possibly a stylesheet or two. Some plugins may require other plugins, so it's important to check out the documentation for any plugins you're considering using to see it's requirements and usage instructions.
You can use jQuery to differentiate the behavior of any external links in your project by having them target new browser tabs instead of navigating away from your site in the current tab.
*hint: use .attr("target","_blank");
Head over the the jQuery Plugin Registry and find an Image Gallery Plugin.