1

Take this code for example:

$('.photo').hover(
            function() {
                //display heading and caption
                $(this).children('div:first').stop(true,false).animate({top:0},{duration:200, easing: 'easeOutQuart'});
                $(this).children('div:last').stop(true,false).animate({bottom:0},{duration:200, easing: 'easeOutQuart'})
})

Lets say I want to know which element was selected with this line:

$(this).children('div:first') 

Is it possible somehow to alert the targeted element? I tried:

something = $(this).children('div:first').val();
                alert (something);

or

something = $(this).children('div:first');
                alert (something);

With the first example I get blank alert. With second - Objext object.

Regards,

Ram
  • 143,282
  • 16
  • 168
  • 197

2 Answers2

1

You can use the following.

something = $(this).children('div:first').text();
                alert (something);

or

something = $(this).children('div:first').html();
                alert (something);
dotcoder
  • 2,828
  • 10
  • 34
  • 50
1

Of course! you can use console.log which works great with jQuery selections.

console.log($(this).children('div:first'));

if you're using firefox or chrome, press F12 to open your developer's console, navigate to the console tab, and you will see your entire selection and structures.

This is highly useful for also showing arrays and objects, and anything, in fact!

Rodik
  • 4,054
  • 26
  • 49