SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Chambéry (France)
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question innerHTML and DOM elements in Safari

    Hello all,

    I'm facing a problem with Safari (Mac) when trying to switch 2 elements innerHTML's and looking for the elements they include with getElementById.

    The browser seems to be unable to find the "divA" element when switching twice. When switching three times, the alert message is correct, the element is found.


    Do someone has any idea about this or any tip to overpass this problem.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Document sans titre</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <script language="JavaScript">
    function switchHTML(el1,el2) {
      var tempHtml = document.getElementById(el1).innerHTML;
    
      document.getElementById(el1).innerHTML = document.getElementById(el2).innerHTML
      document.getElementById(el2).innerHTML = tempHtml;
    }
    function getElement(elt) {
      var myElement = document.getElementById(elt);
      alert (myElement);
    }
    </script>
    <body>
    <div id="div1" style="border:1px solid #dfdf00">div1
      <div id="divA" style="background-color:#dfdfff">divA</div>
    </div>
    <br />
    <div id="div2" style="border:1px solid #dfdfdf">div2
      <div id="divC">divC</div>
    </div>
    <a href="#" onClick="javascript:switchHTML('div1','div2')">switch</a>
    <a href="#" onClick="javascript:getElement('divA')">get element</a>
    </body>
    </html>

  2. #2
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •