tags:

views:

39

answers:

1

I have the following code:

    $(document.body).click(function() {
       $(".content").each(function(i) {
           $(this).
       });
    });

How can I retrieve the value of the first hidden field within $(this)?

+4  A: 

You can use :hidden and :first filter selectors like this:

$(document.body).click(function() {
   $(".content").each(function(i) {
       $(':hidden:first', $(this)).val();
   });
});
Sarfraz
So would I just declare, for example var v = (':hidden:first', $(this)).val();?
George
yes that's right :)
Sarfraz
@Sarfraz - Typo on your third code line, missing the '$'. Also, I might note that '$(this)' is unnecessary there. Using just 'this' would suffice.
BBonifield
@BBonifield: Thanks for that typo info :)
Sarfraz
On the same note, how can I get the first image within this?
George
@George: Just replace `:hidden` with `img`
Sarfraz
@Sarfraz Thanks!
George
@George: Welcome :)
Sarfraz