locked
div is not closing whecn click on out side of document RRS feed

  • Question

  • User81789783 posted

    below div is not closing when click out side of document

    <script>
    
            var list = [];
            var count = 0;
            var listComments = [];
            var currentdate = new Date();
    
            $(document).mouseup(function (e) {
                var container = $("bottomdivselect");
    
                // if the target of the click isn't the container nor a descendant of the container
                if (!container.is(e.target)) {
                    container.hide();
                }
            });
    
    .....................
    
    
    <div id="bottomdivselect" style="display: block; border-style: groove; width: 20rem;">
    
                                <div class="ddlitemvalue">one</div>
                                <div class="ddlitemvalue">two</div>
                                <div class="ddlitemvalue">three</div>
                            </div>

    Sunday, March 24, 2019 12:17 PM

Answers

  • User839733648 posted

    I've tested your code and found you've missed "#" in your jquery code.

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    </head>
    <body>
        <div id="bottomdivselect" style="display: block; border-style: groove; width: 20rem;" > 
            <div class="ddlitemvalue">one</div>
            <div class="ddlitemvalue">two</div>
            <div class="ddlitemvalue">three</div>
        </div>
        <script>
            $(document).mouseup(function (e) {
                var container = $("#bottomdivselect");
                // if the target of the click isn't the container nor a descendant of the container
                if (!container.is(e.target)) {
                    container.hide();
                }
            });
        </script>
    </body>
    </html>

    result:

    Best Regards,

    Jenfier

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 25, 2019 2:44 AM