[英]Hide only click div from echoed php
Before asking this, I have checked here 在问这个之前,我已经在这里检查了
I am very new to php
and JavaScript
. 我是
php
和JavaScript
新手。 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
,当.togBtn
是click
$(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.