简体   繁体   English

隐藏仅回声php中的div

[英]Hide only click div from echoed php

Before asking this, I have checked here 在问这个之前,我已经在这里检查

I am very new to php and JavaScript . 我是phpJavaScript新手。 But the problem here is I echo results from my database with divs example below. 但是这里的问题是我用下面的divs示例从数据库中echo结果。

echo "<div class="togBtn"><div class="result">$results</div></div>";

And the html output is something like html输出类似

<div class="togBtn"><div class="result">firstresult</div></div>
<div class="togBtn"><div class="result">secondresult</div></div>

But i then wrote a JavaScript that toggles .result when .togBtn is click 但我然后写了一个JavaScript是切换.result ,当.togBtnclick

$(document).ready(function() {
    $(".togBtn").click(function() {
        $(".result").slideToggle();
    });
});

But the problem is that when i click the .togBtn , both the div with firstresult and secondresult is toggled . 但是问题是,当我click .togBtn ,具有firstresult和secondresult的div都被toggled My question is, is it possible that when i click .togBtn only that div results is toggled rather than both echoed results. 我的问题是,当我click .togBtn时,是否仅切换了div结果而不是同时echoed了两个结果。 Am echoing the results wrongly such that it causes the problem. 错误地回显结果,从而导致问题。 Any suggestion would do. 任何建议都可以。 Thanks in advance. 提前致谢。

The answer was to use the jQuery .next() .prev() with $(this) 答案是将jQuery .next() .prev()$(this)

$('.togBtn').click(function() {
    $(this).next().slideToggle();
}); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM