Trouble displaying a cloned HTML element

I used jQuery to create a copy of a div and positioned it on the page, but for some reason, it's not displaying. When I checked using F12 tools, all the properties such as top, left, height, and width seemed to be set correctly.

<div id="divLine" style="width: 12px;height:16px;background-color: #000"></div>

 var clone = $("#divLine").clone().prop('id', 1)[0];
            $(clone).css({
                position: 'absolute',

                left: 20,
                top:20
            })

Check out the JSFiddle Example here

Answer №1

Make sure you remember to add the copied element to either the body or the relevant container.

Check out this demo:http://jsfiddle.net/9TP5e/1/

$('body').append(clone);

Answer №2

Failure to attach the clone to its parent element.

Solution available here: http://jsfiddle.net/9TP5e/4/

Please include the following line -

$("#divLine").parent().append(clone);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be causing my CSS/Layout to alter once AJAX/JavaScript has been executed?

When the user clicks, an AJAX call is made to retrieve data from a third-party API. The frontend/layout renders correctly before this action; however, after the data is fetched and displayed in the frontend, the layout changes. Upon debugging multiple tim ...

I am interested in designing an arrow shape with the help of CSS. Kindly refer to the

Can someone assist me in creating a CSS arrow shape that resembles the one shown in this screenshot? Also, I am looking to create next and previous post buttons similar to this. Any guidance would be appreciated. ...

Store additional data with the visitor ID WEB in Fingerprint JS V3

After browsing through similar questions, I couldn't find a solution that fits my needs. Basically, I have a website where a random emoji is generated and stored in local storage. However, this method is not effective as users can easily delete their ...

Struggling to Achieve Consistent Design Across Different Browsers When Styling a Calendar

My webpage has a calendar that retrieves data from the server using Jquery. Interestingly, the calendar looks perfect on Google Chrome but falls apart on Firefox. I can't seem to style it to make it look consistent across different browsers like in C ...

PHP code in Wordpress incorporating an Ajax request

Does anyone know how to fetch user data as a string using ajax in WordPress? I think I understand the basic concept PHP This code goes in my functions.php file add_action('template_redirect', 'edit_user_concept'); function edit ...

Trouble with ajax call in Internet Explorer 8

Seeking assistance with a straightforward ajax request triggered by a user altering a select element. Implemented using jquery .ajax, the current functionality (which works in all browsers except Internet Explorer) involves loading a .html file via ajax, ...

How can I adjust the transparency in a JavaScript popup modal window for an ASP.Net GridView?

Recently, I added an 'onclick' event to every row of an asp gridview and the popup window that appears is functioning perfectly. Now, I'm interested in adding a transparency level to the body of the popup window for a translucent effect. Can ...

What is the process for calculating the total sum of input values utilizing JavaScript?

My JavaScript skills are not perfect, and I'm struggling to calculate the total sum of values in the amount input boxes without refreshing the page. Can someone assist me with this challenge? Thank you. function Calculat ...

"Troubleshooting: Fixing the issue with jQuery datepicker not

After implementing the jQuery Datepicker on a field, I noticed that even though assigning a value to the field shows in Chrome's developer tools... https://i.sstatic.net/We7Ua.png Unfortunately, the assigned value does not show on the front end. I ...

Converting an OpenRasta XML request to JSON for response

I have a simple application using OpenRasta framework with a Home resource containing a single string property called Title (taken from the OpenRasta community documentation example). I've configured both XML and JSON data contracts for this resource ...

Is it feasible to add a row in bold font following every set of 10 rows written in regular text?

Looking for a way to implement pagination on a table with dynamic headers? I am using rows with font-weight:bold to act as headers for the pagination. Is it possible to insert a row with font-weight:bold every 10 rows? I am unsure of how to achieve this, ...

What is the best method for centering text input within an Angular Material toolbar?

Can anyone help me with aligning input elements with buttons on an Angular Material toolbar? Check out the code pen: http://codepen.io/curtwagner1984/pen/amgdXj Here is the HTML code: <md-toolbar class="md-hue-1" layout-align="start center" style="mi ...

Experiencing issues with Jquery Ajax calls causing Internet Explorer to crash?

This is my first time posting on this website, so I apologize in advance if I make any mistakes with formatting. Currently, I am working on developing an MMO using Javascript and jQuery. Everything seems to be running smoothly in Chrome, Safari, Firefox, ...

What is the correct way to create a card outline in Bootstrap?

I am currently developing a Django website to enhance my skills in coding, CSS, Html, and Bootstrap. However, I am encountering an issue with the main page of my site. The visuals on my cards do not align properly with the colored boxes at the top of the p ...

"Trouble with the accordion: How to make the first one open

Is there a way to make the first tab automatically expand when the page is refreshed? I want the General tab to be expanded by default like this: General (top header) (-) lorem ipsum (-) lorem ipsum doller amu site amu doller lorem ipsum (+) lorem i ...

Having trouble with Jquery version 1.5 and the $.load function not functioning

Try running the following code snippet: $('body').load('test.html'); ...

How to create a vertical dashed line using React Native

https://i.sstatic.net/Mhbsq.png Looking for advice on implementing dotted vertical lines between icons in React Native. Any suggestions? ...

Creating sleek HTML5 applications in the Windows 8 Metro style

Is it possible to develop a metro style Windows 8 HTML5 application without having Windows 8 OS installed? I know how to work on VS2012, but since it's a web application, I don't see the need for Windows 8 OS. Please let me know if it's nece ...

Troubleshooting ASP.NET Postback Problems When Loading Dynamic Data in JQuery Dialog

I am aware that similar issues have been discussed on SO before, but none of the solutions provided have helped me with my specific problem. My project involves working with Visual Studio, ASP.NET, and C#. What I need to accomplish is as follows: I have a ...

persistently drifting towards the right despite the absence of direction

Why is the adminbox floating when no command is present? The fixed div center is not functioning properly .adminbox { width: 200px; height: 17px; margin-top: 20px; padding: 20px; font-size: 12px; ...