[英]Expand JSON data onclick
How to expand JSON data on click by id? 如何按ID扩展click上的JSON数据? I got stack with my code, once the button clicked all data expanded, what I want to do is only expanded one data based on an ID I clicked, here my fiddle right now https://jsfiddle.net/zeef/2638rgtz/1/ 我将代码与堆栈放在一起,一旦按钮单击所有数据展开,我想做的只是根据我单击的ID展开一个数据,这是我现在的小提琴https://jsfiddle.net/zeef/2638rgtz/1 /
With is code: 用的是代码:
<script>
function myFunction() {
$('button').toggleClass('active');
$('.title').toggleClass('active');
$('nav').toggleClass('active');
}
</script>
<div class="wrapper">
<div id="entrydata" class="profile">
</div>
</div>
Use DOM navigation relative to the element. 使用相对于元素的DOM导航。
Change your element so it passes this
to the function: 改变你的元素,因此通过this
给函数:
<button onclick="myFunction(this)">
Then use that in the function: 然后在函数中使用它:
function myFunction(element) {
$(element).closest(".content").find("button, .title, nav").toggleClass("active");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.