开发者

jQuery pass value class

开发者 https://www.devze.com 2022-12-31 09:04 出处:网络
$(\".hidee2\").click(function() { var type = $(\".st\").val(); } <f开发者_JAVA技巧orm action=\"\" method=\"POST\"><input type=\"hidden\" class=\"st\" value=\"st\"><div class=\"button\"
$(".hidee2").click(function() {
    var type = $(".st").val();
}

<f开发者_JAVA技巧orm 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! link user click? because i need to pass over the st value? is there any way to achieve this using jquery? currently, only st value is passed over


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

i.e., get the closest form which is parent to the clicked anchor (it's closest ancestor), and from there, traverse downwards to find the child input, and get it's value.

0

精彩评论

暂无评论...
验证码 换一张
取 消