Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


the text method doesn't work in my js file.

// JavaScript Document

  // appending div to the body //

      var $para = $("<p></p>");

     var $image = $("<img>");

      var $overlay = $("<div id='overlay'></div>");

      //                 AdDiNg OvErLaY aNd iMaGe WiTh TeXt             //




     // iMaGe CliCk FuNcTiOn ShOwInG oVeRlAy            //

      $(".pic-nav li a").click( function(e) {


           var loc = $(this).attr("href");

             var captionTex = $(this).attr("alt"); 

            $image.attr("src", loc);




         $image.click( function() {



            ``` js

          this is the whole file.. for the beginning of making a interactive photo album.

3 Answers

David Morisset
David Morisset
13,323 Points

An image can not have children, this is why your paragraph does not appear.

If you want to have an image with a caption, you should use reproduce this kind of markup :

    <img src='image.jpg' alt='alt text' />
    <figcaption>Here goes the caption</figcaption>

which will translate to :

var $fig = ($("<figure></figure>");
var $image = $("<img>");
var $caption = $("<figcaption></figcaption>");


Hope this helps

i was trying to select the caption from the alt attr n the html that the a tag with jQuery

i will post the html soon i have to go to work :(