I am trying to display in a ColorBox popup, a caption AND a title (caption from image 'alt' attribute and title from image 'title' attribute). The colorbox is opened when an image is clicked.

Here is an example of what I want to do.


The img will be something like the following.

<img typeof="foaf:Image" src="http://localhost:4444/img.jpg" width="336"   height="254" alt="LEGEND / CAPTION balbalblalblalba balbalblalblalba balbalblalblalba" title="TITLE balbalblalblalba balbalblalblalba balbalblalblalba" class="">

Do you have any idea of how can I do that?

I am using:

  • Colorbox 7.x-2.10
  • Drupal 7.35

The colorbox module settings are the following.


1 Answer 1


Add "colorbox" class to your element. You could also select by document.getElementsByTagName("img"), but we don't really want to select every single img tag.

var cbox = document.getElementsByClassName("colorbox")

for (var i=0, i < cbox.length; i++) {
  cboxTitle = cbox[i].title;
  cboxAlt= cbox[i].alt;

  cboxTitle = "<span class='title'>" + cboxTitle + "</span> <span class='alt'>" + cboxAlt + "</span>"

You then just got to make colorbox print out the title tag and style it the way you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.