0

I would like to have

album_name = Precious

How do I get that?

<html>
    <head>
        <title></title>
    </head>
    <body>
        <div id="ps_slider" class="ps_slider">
            <div id="ps_albums">
                <div class="ps_album">
                    <div class="ps_image">
                        <div class="ps_img">
                            <img src="puppies/Snoopy/primary.jpg" alt="Dachshund Puppy Thumbnail"/>
                        </div>
                    </div>
                </div>
                <div class="ps_album">
                    <div class="ps_image">
                        <div class="ps_img">
                            <img src="puppies/Precious/primary.jpg" alt="Dachshund Puppy Thumbnail"/>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script type="text/javascript">
        $(function() {
            var $ps_albums      = $('#ps_albums');  

            $ps_albums.children('div').bind('click',function(){
                var $elem = $(this);
                var album_name  = 'album' + parseInt($elem.index() + 1);
                console.log(album_name);
            });

        });
        </script>

    </body>
</html>
0

3 Answers 3

0
$(function() {
    $(".ps_img").click(function(){
       var album = $(this).find("img").attr("src").split("/")[1];
       alert(album);
    });

});
Sign up to request clarification or add additional context in comments.

Comments

0

This should do the trick:

$ps_albums.children('div').bind('click',function(){
  var album_name  = $(this).find('img').attr('src').split('/')[1];
});

Comments

0

Try this:

$(function() {
  $('#ps_albums .ps_album').click(function() {
    var $elem = $(this);
    var $img = $elem.find('img');
    var album_name = $img.attr('src').split('/')[1];
  });
});

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.