简体   繁体   English

单击另一个 DIV 时隐藏/显示 div

[英]Hide/Show div when click another DIV

In my foreach loop, I would like to show the rest 4 elements of the current field when clicks to the first Div it should show the rest 4 fields(DIV) which belongs to that value.在我的 foreach 循环中,当单击第一个 Div 时,我想显示当前字段的 rest 4 个元素,它应该显示属于该值的 rest 4 个字段(DIV)。

 @foreach ( $reled as $rele )
                <div id="MainD">
                <div class="" id="myDIV">
                    <div id="MainD">{{ $rele->customer_name }}</div>
                </div>
                </div>
                <div style="display: none;" id="ShowD">
                <div class="field-item">
                    <div>{{ $rele->customer_name }}</div>
                    <span class="text-muted text-xs">Full Name</span>
                </div>
                <div class="field-item">
                    <div>{{ $rele->amount_word }}</div>
                    <span class="text-muted text-xs">Amount in Words</span>
                </div>
                <div class="field-item">
                    <div>{{ $rele->amount_numb }}</div>
                    <span class="text-muted text-xs">Amount in Numbers</span>
                </div>
                <div class="field-item">
                    <div>{{ $rele->customer_address }}</div>
                    <span class="text-muted text-xs">Customer Address</span>
                </div>
                <div class="field-item">
                    <div>{{ $rele->date_accident }}</div>
                    <span class="text-muted text-xs">Date of Accident</span>
                </div>
                </div>
                @endforeach

Please help me, I am trying JQuery toggle, but it is not working, Please let me know if there is better way to do it.请帮助我,我正在尝试 JQuery 切换,但它不起作用,如果有更好的方法,请告诉我。

My JQuery Code:我的 JQuery 代码:

$(document).ready(function() {
    $('.MainD').on('click', function(){
        $('.ShowD').toggle();
    });
});

You are calling the Class selector when your elements have ID attributes.当您的元素具有 ID 属性时,您正在调用 Class 选择器。

See example.见例子。

 $(document).ready(function() { $('#MainD').on('click', function() { $('#ShowD').toggle(); }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="MainD"> <div class="" id="myDIV"> <div id="MainD">{{ $rele->customer_name }}</div> </div> </div> <div style="display: none;" id="ShowD"> <div class="field-item"> <div>{{ $rele->customer_name }}</div> <span class="text-muted text-xs">Full Name</span> </div> <div class="field-item"> <div>{{ $rele->amount_word }}</div> <span class="text-muted text-xs">Amount in Words</span> </div> <div class="field-item"> <div>{{ $rele->amount_numb }}</div> <span class="text-muted text-xs">Amount in Numbers</span> </div> <div class="field-item"> <div>{{ $rele->customer_address }}</div> <span class="text-muted text-xs">Customer Address</span> </div> <div class="field-item"> <div>{{ $rele->date_accident }}</div> <span class="text-muted text-xs">Date of Accident</span> </div> </div>

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

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