Week 7 – Javascript and JQuery


Javascript is a programming language, just like PHP. It is often used to create reactive websites with animations, effects, moving parts, and things like that.

Variables and functions are both used in javascript, just like in PHP.

Here is an example of the exact same thing being done in PHP, then Javascript, so you can see the difference:


//save my name and print it

$name = “Cassie”;

echo $name;


<script type=”text/javascript”>

//save my name and print it

var name = “Cassie”;



As you can see the same basic principles apply to javascript (functions, variables, etc, all exist, and are used in the same way) but the syntax, the way the code is written, is slightly different.

You can use both Javascript and PHP in one file, if you want to combine examples in your mashup. You can also use just Javascript and jQuery to read information without PHP – do whichever you find the most straightforward, or use both, in your own mashup. Base your work off of whichever examples are closest to your needs.


jQuery is a javascript libarary that you can download and use. What that means is that jQuery is a file that contains a lot of already-written javascript, all enclosed inside a number of functions. You can use these functions to do all sorts of things that would be tricky or time consuming to do on your own.

To use it jQuery you just need to include the jQuery file in your page. Do that like this –

          <script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js“></script>

From then on you can use jQuery functionality inside your javascript code. (If you copy and paste this directly you may have to retype the “s, WordPress does funny things to quotations marks)

jQuery can access elements inside the html of your page based on their class, id, or just type (eg, it could access all the p tags, all the p tags with class “quote”, etc.) After you have selected what item you wish to access, you type a “.” then the function you wish to apply to it. This looks like this:

$(this).hide() – hides current element.

$(“p”).hide() – hides all paragraphs.

$(“p.test”).hide() – hides all paragraphs with.

$(“#test”).hide() – hides the element with id=”test”.

What you’re doing is selecting an element (this is called a document selector) and applying a function to it (these are functions that are built into jQuery). You can find the details of all these functions in the JQuery documentation. hide() is just one example.

jQuery code should go inside a document ready function. This means the jQuery code executes once the page is ready, once every element on it has loaded. If you try to access an element before the entire page is loaded, it can fail and cause problems, which is why we use this function. You can put jQuery code in separate code blocks throughout your html, like with php and javascript, but it is best practice to keep it inside a document ready function. Even though all your jQuery code should go inside this one block, you can still use it to add and change content on your page in any place, by using document selectors to make changes to specific parts of your document. Keeping all your code in the one place also makes it easier to write your html code and read it later without confusing code in the way.

Follow along, here is the complete example code: Basic jQuery Fun (comment out and uncomment various lines of code to see what they all do. There’s a lot more than just this if you check the jQuery documentation for ideas.)

Interactive mashup stuff with jQuery and Ajax – YouTunes

You can use jQuery to get added interactivity quite easily. This example takes us through reading a pipe with javascript and jQuery, allowing the user to select from a drop down list. Ajax is another technology that jQuery is making use of here – don’t worry too much about the specifics, because jQuery handles that all for you!

Pipe: http://pipes.yahoo.com/pipes/pipe.edit?_id=34067198a12660aecbb80cffe8be02d3 

YouTunes example

jQuery plugins

People have made a number of jQuery plugins. These are more pieces of Javascript people have written based on stuff inside jQuery. There tends to be things like gallerys, etc, which you can use for yourself quite easily. Here are some examples:

Javascript resources: 

jQuery resources:

Loads of plugins –


Don’t overcomplicate your own mashups, wherever you can just base your work of the examples we’ve showed you. If you’re doing something beyond what we’ve showed you, make sure you do your own research and thoroughly analyse exactly what kind of work you have to do and whether it’s feasable within the time constraints of this unit. We’d prefer an elegant and functional mashup that actually works over an extremely complex mashup idea that does not work. Focus on creating a good user experience and working within the constraints of what data is available.

If you have problems or are unsure how to proceed with your mashups, don’t hesitate to email me – there’s nothing worse than marking an assignment and finding out someone got stuck on a problem I could have helped them solve if they just told me about it! My email address is on the blackboard contact page.

Things some of you might find useful:

Some HTML and CSS catch up stuff

Some videos to help you jog your memory about HTML and CSS –

HTML & CSS – The VERY Basics

Check this video out if you’ve forgotten the basics – it takes you back to the verys tart.

Google: HTML, CSS and Javascript from the Ground Up

Watch the HTML and CSS videos here, and have a go at the exercises if you’re still feeling a bit shaky. Watch the Javascript videos if you would like to start getting a handle on that too.

Week 2

Welcome to week 2. As you ease back into the idea of developing for web, it might be valuable to brush up on your HTML and CSS skills. Here are some useful resources:

W3Schools – Great site for getting a handle on the basics.

Net Tuts – Loads of more advanced tutorials, tips, tricks, and articles

A List Apart – A great site with content from CSS positioning basics to thoughtful articles on new web technologies and the design process.

And why not practice your CSS skills on the css Zen Garden?

Things you might want to install:

Firebug – A browser extension that lets you see the underlying html and css on a web page. Perfect for debugging your site. You can highlight something on a page and firebug will show you where in the code that thing is being styled. This will make your life so much easier!

Web Developer – A browser extension that has so many useful features I can’t list them all. You can toggle things like css or images on or off, you can instantly resize your browser window, it can outline block elements so you can easily see how your page is structured, and a lot more. Download it and have a play.

Komodo Edit – If you don’t already have a preferred text editor, this is a nice once.

There are a lot of CSS and HTML resources out there – if you ever get stuck, try googling your problem – you’ll be surprised how many people out there might have struggled with the same thing, and have solutions to offer!

And finally, some valuable insights: The Web Design Community Offers Advice To Beginners

And remember your to do list for this week:

  • Set up your Tumblr, and post the URL on the discussion board
  • Post your Daily Depictions (see the Week 1 lecture notes in case you don’t know what to do) and reblog with some commentary on one of your classmate’s!
  • Post your research and ideas about the top 6 new things on the web to get you started for poster submissions in Week 4.