Error in IE when inserting value to an empty span

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Stale
    New Member
    • Oct 2007
    • 11

    Error in IE when inserting value to an empty span

    When you insert value to an empty span in IE, the browser will not add the needed space between spans.

    Example:

    [HTML]<script>
    function btnclick()
    {
    document.getEle mentById("sp2") .innerHTML="KIN G"
    }
    </script>
    <span id="sp1">Elvis </span>
    <span id="sp2"></span>
    <span id="sp3">Presle y</span>
    <input type="button" onclick="btncli ck()" />
    [/HTML]




    When you push the button, "KING" is inserted in the secong span, like this

    Elvis KINGPresley

    with no space between KING and Presley

    Anyone knows a way around this?
    Last edited by acoder; Oct 31 '07, 08:16 AM. Reason: Added code tags
  • mrhoo
    Contributor
    • Jun 2006
    • 428

    #2
    either set a left margin for the span or include a space in the text

    Comment

    • Stale
      New Member
      • Oct 2007
      • 11

      #3
      Thank you for your reply.

      But this should not be necessary.
      I think that IE "forgets" to set the span's status to "not empty" when the script fills it with value.

      There should be a way to tell IE that the span element is no longer empty...

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by Stale
        I think that IE "forgets" to set the span's status to "not empty" when the script fills it with value.

        There should be a way to tell IE that the span element is no longer empty...
        I'm afraid IE 'forgets' a lot of things.

        What do you mean by "not empty"? It does fill the span with the value. Does the source code show the span bunched up next to the other spans with no spaces in between them?

        Comment

        • Stale
          New Member
          • Oct 2007
          • 11

          #5
          Yes it does fill the span with value, but the 2nd and 3rd span is displayed with no space between them.

          So, the main problem is that IE shows the result differently if YOU write "KING" inside the span or if the SCRIPT writes "KING" inside the span.

          In the source code the 3 spans are written in 3 lines. The result IS the same if you write the code on one line, with space between each span.

          Comment

          Working...