Absolutely Position a Cloned Element in jQuery
Hi
I'm trying to absolutely position a cloned div with jQuery. When I add CSS to the cloned element with the .css() method it only moves the text (even if I copy all of parent element's CSS into this object).
I have a fiddle here : https://jsfiddle.net/emilychews/xuup6va1/3/
If you click on the blue div it creates a clone.
I've also put the code below for quick reference.
HTML:
- <div id="wrapper">
- <div id="testdiv">
- <h1>I am a div</h1>
- <p>with a blue background</p>
- </div>
- </div>
CSS:
- #wrapper {width: 100%; height: 100%;}
- #testdiv {
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- margin-top: 20px;
- box-sizing: border-box;
- padding: 10px;
- background-color: blue;
- color: white;
- height: 350px;
- width: 300px;
- }
jQuery:
- $('#testdiv').click(function() {
- $( this ).clone()
- .insertAfter('#testdiv');
- });
Any help would be awesome,
Emily