Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8550851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:03:28+00:00 2026-06-11T14:03:28+00:00

Upon clicking on one of the rounded rectangles in the following code, it is

  • 0

Upon clicking on one of the rounded rectangles in the following code, it is required to create a copy of the span element and place it on top of the original element. The code does that, but the new element has an increased height. Please suggest what could go wrong.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<body>

<div id="phrasesDiv" style="line-height:250%" /></div>

<style type="text/css">
.phrase {
    font-size:18pt;
    color:blue;
    background: palegreen;
    border:2px solid green;
    padding:2px 10px 2px 10px;
    -webkit-border-radius:10px;
}
</style>

<script type="text/javascript">

{
    // create the phrase list dynamically
    var phraseList = "Apple~Orange~Kiwi~Guava";
    var phrasesDiv = document.getElementById("phrasesDiv");
    var phrases = phraseList.split('~');
    for (var i=0; i<phrases.length; i++)
        phrasesDiv.innerHTML += "<span id=\""+phrases[i]+"\" class=\"phrase\" onmousedown=\"phraseTouched('"+phrases[i]+"')\">"+phrases[i]+"</span>&nbsp;&nbsp;&nbsp;\n";
}

function getDim(el) {
    var lw = el.offsetWidth;
    var lh = el.offsetHeight;
    for (var lx=0, ly=0; el != null; lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);
    return {x:lx,y:ly,w:lw,h:lh};
}

function phraseTouched(id) {
    var elem = document.getElementById(id);
    var dim = getDim(elem);
    var dragElem = document.createElement('span')
    dragElem.id = id+"_copy";
    dragElem.innerHTML = id;
    dragElem.className += " phrase";
    dragElem.style.background = "pink";
    dragElem.style.position = "absolute";
    dragElem.style.left =  dim.x+"px";
    dragElem.style.top =  dim.y+"px";
    elem.parentNode.appendChild(dragElem);
}

</script>

</html>

EDIT: The following function worked … but I am still curious to know why am I getting an increased height if I add to the div programatically.

function phraseTouched(id) {
    var elem = document.getElementById(id); 
    var dim = getDim(elem); 
    document.body.innerHTML += "<span id=\"_"+id+"\" class=\"phraseDrag\" style=\"left:"+dim.x+"px;top:"+dim.y+"px;position:absolute;\">"+id+" </span>\n";  
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:03:30+00:00Added an answer on June 11, 2026 at 2:03 pm

    Simply put, you break out the standard layout model when you add that nasty “position: absolute” property to your element and it doesn’t know how to represent itself. If you want to maintain most of the styling, the easiest fix would be to simply add:

    display: inline-block;
    

    somewhere in your .phrase style, at least that’s what I would do.
    Of course Vijay’s solution works as well as long as you don’t mind losing that line-height property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, my hope was to create a checkbox that upon clicking would call a
I have one form that opens another form upon clicking a button. When the
I tried the following code to get an alert upon closing a browser window:
I have 4 radio buttons in one group. Upon clicking the radio button the
I have two ImageButtons on my page. Upon clicking one, I want to hide
Upon clicking on a link, I am bringing in some images from a JSON
In my application, upon clicking login in the login page, I have to call
I'm trying to get d3 to change the color of plot points upon clicking
I have an aspx page on which I have 2 static jquery tabs.Upon clicking
I'm using the jquery-ui dialog box . My problem is upon clicking the x

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.