简体   繁体   中英

Setting display to none remove the svg element from DOM

Setting display to none using jquery or javascript removes the svg element off the DOM. This is strange.

I am trying show a pop up dialog with ok and cancel buttons using jquery which works, but after clicking any of the buttons its deleting the whole svg element from DOM

Code:

<div id="dialog" class="bs-example web_dialog">
    <form>
        <div class="form-group">
            <div class="col-lg-4" style="left: 173px; top: 258px; visibility: visible; position: absolute; overflow: visible; border: 1px solid #C5C5C5">
                <label for="inputEmail">Unique Id/Mobile Number:</label>
                <input type="number" class="form-control" id="inputEmail" placeholder="Unique Id" width="10px">
                <label for="inputPassword">Document URL</label>
                <input type="url" class="form-control" id="inputPassword" placeholder="URL">
                <br>
                <div class="btn-sm">
                    <button type="submit" id="btn_save" class="btn btn-primary btn-sm">Ok</button>
                    <button type="submit" id="btn_cancel" class="btn btn-primary btn-sm"  onclick="closePopUp(event)">Cancel</button>
                </div>
            </div>
        </div>
    </form>
</div>

<button type="submit" id="btn_cancel" class="btn btn-primary btn-sm"  onclick="closePopUp()">Cancel</button>

function closePopUp()
{
    document.getElementById('dialog').style.display = 'none';
}

Executing the above is removing svg element off the DOM

pressing a submit button in a form is the problem. even though the form element has none of the usual attributes for a form attribute, pressing a submit button will reload the page

option 1: don't use unless you are submitting data

option 2: return false in the submit buttons onclick

go with option 1 every time :p

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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