JQuery pass value class

$(".hidee2").click(function() {
    var type = $(".st").val();
}

<form action="" method="POST"><input type="hidden" class="st" value="st"><div class="button">Room Status : Accepting Reservation <br /><span><span><a class="hidee2">Book Now!</a></span></span></div></form>

<form action="" method="POST"><input type="hidden" class="st" value="st2"><div class="button">Room Status : Accepting Reservation <br /><span><span><a class="hidee2">Book Now!</a></span></span></div></form>

<form action="" method="POST"><input type="hidden" class="st" value="st3"><div class="button">Room Status : Accepting Reservation <br /><span><span><a class="hidee2">Book Now!</a></span></span></div></form>

      

How do I get which book now! click a user link? because i need to pass st value? is there a way to achieve this using jquery? currently only st value is passed

+2


a source to share


1 answer


$(".hidee2").click(function() {
    var type = $(this).closest("form").find(".st").val();
});

      



ie, get the closest form that is the parent of the clicked anchor (closest ancestor) and from there go down to find the child input and get its value.

+1


a source







All Articles