Interactive Tracker Boxes #4 - jQuery
Submitted by Yorkiebar on Friday, September 26, 2014 - 10:51.
Introduction:
This is the final part of my mini-series explaining how to create interactive tracker boxes in HTML, CSS, and jQuery to allow HTML content to change once the user interacts with the boxes. This part is will explain the final step, jQuery.jQuery Installation:
To begin using jQuery within our file, we first need to link it. We can either download and include the jQuery files, or we dynamically link our page to the official jQuery files hosted on a server by going to the official jQuery downloads page; http://jquery.com/download/, and copying the CDN links;
(Ensure you add 'http:' to the beginning of the source URLs if required!).
Simply write those within the 'head' tags of our page.
Now we are ready to being using jQuery.
jQuery:
Again, within the 'head' tags of our page (because this is function code, and not direct HTML elements for the page display - which all go within the 'body' tags of our page), we want to first write the appropriate 'script' tags to start Javascript functionality... Now we want to write the document ready function, this will automatically execute once the page loads in the user's browser...- $(function() {
- });
- $('.box').click(function() {
- });
- var box = $(event.target)[0];
- var id = box.id;
- var heading = $('#informationTitle');
- var content = $('#informationParagraph');
- var newTitle = $('#title' + id).html();
- var newPara = $('#para' + id).html();
- $(heading).html(newTitle);
- $(content).html(newPara);
Finished!
Add new comment
- 25 views