In Jquery 1.9.1 version,
var dialogDiv = $(`.dialog`).clone().show();
.dis-none {
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="dialog dis-none">
<div class="boxcontent">content</div>
</div>
This will display the dialog content even if the dis-none class is not removed.
But why it is not working in 3.7.1 jQuery version??
In the lower version(1.9.1), the dialog div is cloned and appended to DOM and also displayed without any issues even if the dis-none is present because the show method overrides the effect of dis-none.
But in Upper version(3.7.1), the same code is not working as expected.
But What my question is without removing the dis-none class, is it any way to display the content with show method???
2
Answers
A cloned HTML has no meaning until it is appended to the DOM. You are just cloning the div HTML and trying to show it while it’s not present at all in the DOM.
A sample code regarding how it will work:
First, great for getting the jQuery version updated, it will be faster and more secure and have more features.
.Show()
applies to that clone not the original DIV you cloned from.So, let’s address each of those in turn in code starting with some text just to show what is going on.
I added some comments in the code for some examples.