Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now

Changing the state of the clicked dot


From:

Create an Interactive Map with jQuery and Dreamweaver

with Chris Converse

Video: Changing the state of the clicked dot

Now we have the JavaScript in place that's paying attention to the form element and making sure that when it changes we show and hide the different dots. Now we want to add a script that's going to pay attention to the dots and check to see if the user clicked on them. So let's come back to the interactive_map.js file. Now inside of here I am going to clean up the formatting here a little bit, get rid of some of the whitespace, get rid of some of these extra lines. I am doing this because I need to make sure that I add the click events for the anchor tags inside of the document ready but outside of the mapForm.
please wait ...
Watch the Online Video Course Create an Interactive Map with jQuery and Dreamweaver
1h 12m Intermediate Mar 24, 2011 Updated Aug 31, 2011

Viewers: in countries Watching now:

In Create an Interactive Map with jQuery and Dreamweaver, Chris Converse shows how to design and create a rich interactive map for a web site using the open-source scripting library jQuery and the tools in Dreamweaver. The course covers creating web-optimized images using the slicing tools in Photoshop, implementing the HTML and CSS to assemble an infographic page layout, and adding interactivity with JavaScript and jQuery's fast and concise code library. Exercise files are included with the course.

Take a look at the finished web site here.

Topics include:
  • Preparing web graphics
  • Preparing the base container
  • Manipulating links with CSS
  • Adding a drop-down menu
  • Downloading jQuery and adding interactivity to a project
  • Creating city details
  • Overriding click events of anchor tags with jQuery
  • Enhancing the design with CSS3
Subject:
Web
Software:
Dreamweaver jQuery
Author:
Chris Converse

Changing the state of the clicked dot

Now we have the JavaScript in place that's paying attention to the form element and making sure that when it changes we show and hide the different dots. Now we want to add a script that's going to pay attention to the dots and check to see if the user clicked on them. So let's come back to the interactive_map.js file. Now inside of here I am going to clean up the formatting here a little bit, get rid of some of the whitespace, get rid of some of these extra lines. I am doing this because I need to make sure that I add the click events for the anchor tags inside of the document ready but outside of the mapForm.

So let's hit a few returns. So again I am outside of the mapForm but inside of the ('document').ready. Let's start by typing $('a.dot') as a string literal, so for every time there is an anchor tag with a dot class, outside of the parentheses we are going to type .click();. Inside of the click we are going to type function(), beginning and ending bracket.

Let's split that open. So every time somebody clicks on that dot, we want to do these instructions. So first let's type an alert, just to make sure this is working properly. Inside the parentheses, inside of alert, let's type $(). I am going to type the word "this." So since we are assigning a click to everyone of the anchor tags with a dot class, by returning "this," this is going to let us know the exact dot that was actually clicked on.

So regardless of how many dots are on the map, when we type "this," it's going to return whatever one actually triggers this click event. So after the "this," we are going to type .attr(). Inside of attr, for attribute, two tick marks for a string literal. We are going to type "city," which is the name of the attribute we put inside of every one of the anchor tags. Let's choose File > Save All.

I still have the file running in my browser, so let's go over to our browser. Let's hit Reload. Now if I click on the dot, it should give me a pop-up window that tells me that dot I clicked on. So there is New York city. There is Rome. There is Tokyo. So the click events are working. Let's go back to our JavaScript. So the first thing I want to do when somebody clicks on that dot is I want to change the color. So let's start by $('a.dot').

What we are going to do is set .removeClass('selected');. This is the name of that CSS class we created that takes the PNG file in the background and moves it -40 pixels on the Y, turning the selection green. We are going to go through first and make sure that none of the dots have that class assigned.

Next line $(this).addClass('selected');. Lastly, let's delete the alert. So now what's going to happen is every time somebody clicks on an anchor link, every one of the dots is going to have the class of selected removed, and then we are going to add "selected" to whatever dot was actually clicked.

Let's choose File > Save All. Let's go back to our browser. Let's hit Reload. Now if I click on the dot, whatever dot I click gets the selected class applied to it, and it turns green. And when I click another dot, whatever dot was green gets reset because we are taking that class off of all of the dots and then assigning it to the one we clicked on. So this gives us gives us direct user feedback based on the dot they clicked, in addition to the map function automatically changing the state of the dots and changing itself, which is built into the HTML forms.

In the next movie, we are going to go grab the HTML content and add it into the city detail area.

There are currently no FAQs about Create an Interactive Map with jQuery and Dreamweaver.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Create an Interactive Map with jQuery and Dreamweaver.

Return to your organization's learning portal to continue training, or close this page.


OK

Upgrade to View Courses Offline

login

With our new Desktop App, Annual Premium Members can download courses for Internet-free viewing.

Upgrade Now

After upgrading, download Desktop App Here.

Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Start your FREE 10-day trial

Begin learning software, business, and creative skills—anytime,
anywhere—with video instruction from recognized industry experts.
lynda.com provides
Unlimited access to over 4,000 courses—more than 100,000 video tutorials
Expert-led instruction
On-the-go learning. Watch from your computer, tablet, or mobile device. Switch back and forth as you choose.
Start Your FREE Trial Now
 

A trusted source for knowledge.

 

We provide training to more than 4 million people, and our members tell us that lynda.com helps them stay ahead of software updates, pick up brand-new skills, switch careers, land promotions, and explore new hobbies. What can we help you do?

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.