Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

DOM element hinting

From: Dreamweaver CS5.5 New Features

Video: DOM element hinting

If you've spent any amount of time hand-coding sites, you understand that often it's the little things that mean a lot. So Dreamweaver's new code hinting for DOM element scripting may seem minor at first, but it's something that can really speed up your JavaScript coding. Let's take a look at how it works. So I have the resources.htm open from the 02_05 folder. Now, the first thing I want to point out is that I have a link to a JavaScript file called hinting_test.js in the code of my document.

DOM element hinting

If you've spent any amount of time hand-coding sites, you understand that often it's the little things that mean a lot. So Dreamweaver's new code hinting for DOM element scripting may seem minor at first, but it's something that can really speed up your JavaScript coding. Let's take a look at how it works. So I have the resources.htm open from the 02_05 folder. Now, the first thing I want to point out is that I have a link to a JavaScript file called hinting_test.js in the code of my document.

So if I switch over to Source Code and scroll up, you guys can see there is the link to my external script file. Okay. So I am going to switch over to hinting_test.js. And the reason that I externalized this JavaScript is not only is that usually a good idea, but it's also going to show you that Dreamweaver will go ahead and introspect documents that are linked to this and provide different IDs and class names for us from the parent document. So here I have a function called changeColor, and it's fired when the page is loaded, so I am just going to go ahead and place my cursor inside the function brackets, and I am going to start by creating a variable.

So, var targetElement, and I need to go ahead and set this value. Now, I want to target specific elements on the page, and I want to target any element that has an ID of pageID. So to do that, I am going to type in 'document' and my code hinting comes up, and now I want to do getElementById, so I can just type in 'get' and I am going to let code hinting handle the rest of this for me. So if I hit Return or Enter, it will finish that for me, and now I need to go ahead and give it an ID. Now, what if I don't have all the IDs in my parent document memorized? Well, if I type in a quotation mark, I now get a list of all of the IDs in my parent file.

This is really cool! So I can scroll down through the list and I can find pageID, because remember, that's the one we're looking for. If I hit Return or Enter, now all I have to do is close my parentheses and type in a semicolon. All right! Now, we need to go ahead and change its color, so I'm going to go down to the next line and I'm going to type in 'targetElement.style.color = "red"'. All right, cool! So code hinting helped with that entire process, but the really cool thing there was going out to my parent page and grabbing the pageID from the code.

So I'm going to go ahead and save that, and then I want to preview this in a browser, and when I do that, I can see the element that has the pageID is now red. So let's go back in our code, and let's check out some of the other code hinting improvements that have been made. So the next thing I want to do is I want to get rid of this getElementById, and let's try getting elements by their tag name. So I'm going to type in 'document.getElementsByTagName', and now when I type in a single quote, I get an entire list of HTML elements.

This is the same list that you get when you're hand-coding in Dreamweaver in just a normal HTML document, so they've added that as well. And now I just want do maybe all heading 1s. So I'm going to do h1 and hit Return and then close my parentheses. Now, obviously we're going to get more than one of those, so I need to create a for loop that's going to loop through them and apply the color to each one of these. So just on top of my target element, I'm just going to go ahead and create a loop. So I am going to do for(var i=0; and I am going to make i

Now, I am going to ahead and place the style assignment inside my for loop. And of course I need to reference each item in the array that's returned, so I'm just going to go ahead and in bracket notation pass i in. Okay. So now let me go ahead and save this and preview this in the browser as well. And now if I scroll down, I can see that all the heading 1s on the page are now red. Perfect! Now, in addition to giving you a list of tags and giving you a list of IDs, it will also introspect all of your class names from your file as well.

So I now want to go ahead and get rid of my getElementsByTagName, and I'm going to change that to getElementsByClassName. Now, if you're wondering, it does support both the document.getElementsByClassName as well as the element.getElementsByClassName, so it will work both ways. Again, if I type in a single quotation mark, now I get all of the classes in my document. I can see that I can just scroll through all of them. And I'm just going to do accent, the first one that comes up. And now I'll close my parentheses, and we shouldn't need to change anything down here.

So I'm going to go ahead and save that, preview that in the browser, and now you can see that only where the accent class has been applied, which has been applied to this header and this header, is red. Cool! So this code hinting works for getElementById, getElementsByName, getElementsByTagName, and getElementsByClassName. What this really means more than anything else is that when you're scripting, you're going to be able to speed up the process of targeting elements on your pages, even when you're working in remote files. Dreamweaver's ability to introspect those pages and then return elements and their IDs and then classes will really just end up being one more of those little things that Dreamweaver does to help speed up your development process.

Show transcript

This video is part of

Image for Dreamweaver CS5.5 New Features
Dreamweaver CS5.5 New Features

18 video lessons · 12669 viewers

James Williamson
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
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

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 Dreamweaver CS5.5 New Features.

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


OK
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?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

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:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

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.