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! While you're at it, check out some resources Treehouse students have shared here.

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

JavaScript

Append image to modal.

Hey guys. I'm working on a web shop and I'm having some problems. I'm working with Foundation 5 and I have a Reveal.js plugin, it works and all that, just not the way I want it to.

I have several products which are mostly similar, therefore I've added the classes that are the same for every item, in Jquery so that I don't have to repeat the same code over and over again in the HTML. Now to the problem. I want the Modal to show info for all the items uniquely, so I want to append the unique price, the product image and the product name to the modal box on click. (From the storeItems class in HTML-markup where every item contains this information.) How do I do this and would you mind telling me if I'm at least on the right track?

    $(document).ready(function(){

//STORE ITEM--------------------------------------------------------------->

        var $productItem = $(".storeItems");
        var $productImage = $("#productImage");
        var $productPrice = $(".productPrice");
        $productItem.addClass("large-4 small-6 columns");

//MODAL POPUP-------------------------------------------------------------->

        var $myModal = $("#myModal");
        var $imageContainer = $(".imageContainer");
        var $productPriceContainer = $("#productPriceContainer");
        var $productNameContainer = $("#productNameContainer");

        $productItem.click(function(){
        $productImage.prepend("$imageContainer");
        });
    });

No one has any ideas? Am I submitting this wrong? :(

It's been 3 days now and it's driving me insane. I have 9 different items on the front page and they all have the same attributes, what differs them from each other is the price, the image and the name. When I press the first item, I want a modal with the first items name, price and image in it. When I press the second image, I want the modal to contain the second items info instead. Is there no easy way of doing this? Am I way off with my attempt above? Someone please. :(

I figured it out on my own, thanks anyways guys. Now, how do I remove this ticket? :) //David