Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
>> If you have sites you maintain that never have attributes added to the images you may have a lot of work ahead of you since we've seen that alt text really need to be tailored to each individual image there is no way you can automate adding it to existing pages but there are some tricks you can do in Dreamweaver using find and replace that can speed it up quiet a bit. If you're following along in the exercise files, open oldpage.html from he 0603 folder of the chapter six exercise files.
This page imitates the home page of the site we have been working on but it uses table base markup and spacer GIFs to create the formatting. Go to the edit menu and choose find and replace. In this example we will only be finding the text in the current page but if you are trying to change the alt text throughout a site you will click on the find in menu and choose entire current local site. Again in this example keep it set on current document.
Next in search menu choose specific tag. The fields in the dialog box change as soon as you select this option. There is now a select menu next to the specific tag option that we just chose. Click on that menu, scroll down and chose the IMG element. This will search for images but we but want to find every image only images without alt attributes. So in the menu under the specific tag option click on the arrow and choose without attribute, in the menu beside that click on the arrow and choose alt.
So now we are looking for images without alt attributes. Again though we can't use the same alt text for every image without an alt attribute, so let's first look for all the spacer GIFs and set all of there alt attributes to empty. Although we know we're looking for the image spacer.gif we don't know what the patch of the image will be on any page in our site. Sometimes the path could be just spacer.gif other times it could be images-spacer.gif or .. /images/spacer.gif.
We need a way to find every source attribute that ends in spacer.gif. So the solution is to use a regular expression. This is a set of special characters that let you find patterns within the test. Click on the use regular expression at the bottom of the dialog box then go back up and click on the plus button and then select the adjacent menu, scroll down and select SRC for source, leave the equal option set and then in the final box is where we'll need to type our regular expression to find all of the spacer GIFs no matter what the path to them is.
In regular expressions a period stands for a single character such as a letter, number or punctuation mark. An asterisk means find the preceding character zero or more times. So if we combine a period and an asterisk it basically means match any character zero or more times. By themselves these two characters would match everything but if we add the name of the file on the end spacer.gif the search will yield every path that leads to that file.
So in this box type a period and an asterisk then spacer.gif. Finally we need to tell Dreamweaver what to do when it finds every spacer.gif. Choose set attribute from the action menu. In the adjacent menu click on the arrow and choose alt, leave the final two fields blank so that the attribute will be kept empty to denote it's an image that doesn't convey any information and should be skipped over.
Now we can click on the replace all button. The results panel shows all of the images that were affected. You can see each one of them now has an at attribute set with no content in it. But we don't have to use this method just to find decorative images. You can use the find and replace dialog box with regular expressions to find all the instances of the logo throughout the sight and to set its alt text correctly. Open the edit menu again and choose find and replace, leave current document selected and in the search menu choose specific tag.
The same values that we just used are retained. This time we are going to be looking for all of the logo images so in the field where dot asterisk spacer.gif is replace just the spacer.gif part with logo.gif again this will find all of the logo images throughout the site no matter what the path is to get to them. This time we don't want the alt attribute to be blank so in the two menu type town of Wardscott then click replace all.
Since we only searched in this document only one image was replaced but you can see in the results panel that it now has the alt text correctly set. If you are going to be reusing this search on multiple sites it would be a good idea to save your settings. Open up the edit menu and click on find and replace. In the search menu choose specific tag. All of our settings are still retained, if we wanted to save them to use again later we should click on the floppy disc icon to save the quarry.
The file folder icon folder beside it allows us to load a quarry that we already saved. So although adding alt attributes to an old site is going to require some time and work you can speed it up considerable using Dreamweaver find and replace. Next we'll look at another type of alt text, this time for image maps.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
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.
Your file was successfully uploaded.