Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

image_tag with popup for alt attribute (See related posts)

Firefox doesn't display a popup for the alt attribute for images. While this is according to spec, it's slightly annoying to put the same text in both the alt and the title. Put the following in your ApplicationHelper to copy the alt to the title for every image. Please don't tell me how wrong this is. I don't care.

module ApplicationHelper
  def image_tag(location, options)
    options[:title] ||= options[:alt]
    super(location, options)
  end
end

Comments on this post

moneypenny posts on Oct 31, 2006 at 21:10
You might have it check to see if options[:title] is blank, so that it doesn't overwrite it if the user has specified it already.
timmorgan posts on Nov 01, 2006 at 16:08
Yes, good catch.

You need to create an account or log in to post comments to this site.


Click here to browse all 4860 code snippets

Related Posts