문제

I have a comment section on a website. People can leave comments. Now, I added a reply link to each comment left so that people can reply to a specific comment. When they click on the reply link, the div containing the form for them to answer should show up right under the reply link. This is my code but it just won't work. I have looked online and tried implementing different answers but for some reason I can't make it work.

HTML

<a href="#1" class="show_hide"><span>Reply</span></a>
<div class="answer_div">
<span class="answer_text">Reply</span><br><br>
<form name="form" id="form" method="post" onsubmit="return validation()" action="/action_form.php?id=<?php echo $id; ?>">
<textarea name="comment" id="comment" rows="4" class="comment_class"></textarea><br>
<input class="submit" value="Submit" type="submit"/>
</form>
</div>

Javascript:

Javascript:
$(document).ready(function () {
var $slides = $(".answer_div").hide();
$(".show_hide").show().click(function () {
    var $slider = $(this).next(".answer_div");
    if (!$slider.length) {
        $slider = $(this).closest(".answer_div");
    }
    $slides.not($slider).stop(true, true).slideUp();
    $slider.stop(true, true).slideToggle();
});
});

Thank you!

도움이 되었습니까?

해결책

You are making use of JQuery. So please add the below code between your <head> and </head> tags in your HTML page and it will work with your existing code.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top