Exapand glyphicon-plus glyphicon-plus when collapsed on button click

Benjoe 431 Reputation points
2023-03-24T19:53:12.94+00:00

I have a page with bootstrap glyphicon-plus glyphicon-minus in a span with a class. when the page loads the span is collapsed by default and I need to Expand it on a button click programmatically.

I am doing
 $("#btn-search").click(function () {

$('myclass').find('span').closest('.glyphicon-plus').removeClass();
});

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,454 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
974 questions
{count} votes

Accepted answer
  1. Lan Huang-MSFT 29,246 Reputation points Microsoft Vendor
    2023-03-27T05:43:37.43+00:00

    Hi @Benjoe,

    You'd better provide your complete code or the problem you are currently facing.

    I wrote a demo according to your needs, you can refer to it.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <style>
            #toggle-view .panel {
                margin: 5px 0;
                display: none;
            }
        </style>
    
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
        <script>
            $(document).ready(function () {
    
                $('#toggle-view li').click(function () {
    
                    var text = $(this).find('div.panel');
    
                    if (text.is(':hidden')) {
                        text.slideDown('200');
                        $(this).find('span').removeClass("glyphicon glyphicon-plus glyph-plus-toggle").addClass("glyphicon glyphicon-minus glyph-minus-toggle");
                    } else {
                        text.slideUp('200');
                        $(this).find('span').removeClass("glyphicon glyphicon-minus glyph-minus-toggle").addClass("glyphicon glyphicon-plus glyph-plus-toggle");
                    }
    
                });
    
            });
        </script>
    </head>
    <body>
    
        <form id="form1" runat="server">
            <h2 class="h2-finder">Used cars</h2>
            <ul id="toggle-view">
                <li class="li-toggle">
                    <h3 class="toggle-h3">Title 1<span class="glyphicon glyphicon-plus glyph-plus-toggle"></span></h3>
                    <div class="panel">
                        <span>qwertyuiopasdfghjklzxcvbnm</span>
                    </div>
                </li>
            </ul>
        </form>
    </body>
    </html>
    
    

    11

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Benjoe 431 Reputation points
    2023-03-31T00:58:41.9333333+00:00

    Hi @Lan Huang

    I can only hide the other parents with jquery which works. All that I need is to include the children also

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.