Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


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 :(