Finding the id of a parent div using Jquery

前端 未结 9 1092
失恋的感觉
失恋的感觉 2020-11-29 17:00

I have some html like this:

Volume =

9条回答
  •  猫巷女王i
    2020-11-29 17:21

    JQUery has a .parents() method for moving up the DOM tree you can start there.

    If you're interested in doing this a more semantic way I don't think using the REL attribute on a button is the best way to semantically define "this is the answer" in your code. I'd recommend something along these lines:

    and

    $("button").click(function () {
        var correctAnswer = $(this).parent().siblings("input[type=hidden]").val();
        var userAnswer = $(this).parent().siblings("input[type=text]").val();
        validate(userAnswer, correctAnswer);
        $("#messages").html(feedback);
    });
    

    Not quite sure how your validate and feedback are working, but you get the idea.

提交回复
热议问题