Changing text between <div>'s

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • HikksNotAtHome

    #46
    Re: Changing text between &lt;div&gt;' s

    In article <20040102193706 .21457.00003142 @mb-m10.aol.com>,
    hikksnotathome@ aol.com (HikksNotAtHome ) writes:
    [color=blue]
    >Another alternative might be to compare the previous innerHTML to the latter
    >innerHTML though. If they don't match, then it didn't work:[/color]

    That should read "If they match, then it didn't work"

    --
    Randy

    Comment

    • Lasse Reichstein Nielsen

      #47
      Re: Changing text between &lt;div&gt;' s

      hikksnotathome@ aol.com (HikksNotAtHome ) writes:
      [color=blue]
      > While I am gracious to have my name mentioned in it, I can't claim
      > credit for it. It came from the metallusions website, I only
      > stumbled on it (IIRC, someone else pointed me to it).[/color]

      It is a fairly obvious approach. I have several different versions
      of user-defined getElementById methods (and addEventListene r is a
      personal favorite too).
      [color=blue]
      > Another alternative might be to compare the previous innerHTML to the latter
      > innerHTML though. If they don't match, then it didn't work:[/color]

      You can also (safely, I think) assume that a value gotten from the
      innerHTML property can be put back in and give the same result.
      [color=blue]
      > function insertHTML(elem ,newHTML){
      > tempVar = document.getEle mentById(elem). innerHTML;
      > document.getEle mentById(elem). innerHTML = newHTML;
      > if (tempVar == document.getEle mentById(elem). innerHTML) {alert('It failed')}
      > }[/color]

      This only thsts the ability to change, not to change correctly :)
      It is probably enough, but you can do a test like this;

      <div id="dummy">som e <em class='dummyCla ss'>dummy</em> text</div>
      <script type="text/javascript">
      var elem = document.getEle mentById("dummy ");
      var oldIH = dummy.innerHTML ;
      dummy.innerHTML = "some <strong>other </strong> text";
      var newIH = dummy.innerHTML ;
      dummy.innerHTML = oldIH:
      var oldIH2 = dummy.innerHTML ;
      var IHworks = oldIH != newIH && oldIH == oldIH2;
      </script>
      If setting and reading innerHTML works, this is even non-destructive.


      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • HikksNotAtHome

        #48
        Re: Changing text between &lt;div&gt;' s

        In article <ad557spe.fsf@h otpop.com>, Lasse Reichstein Nielsen <lrn@hotpop.com >
        writes:
        [color=blue][color=green]
        >> Another alternative might be to compare the previous innerHTML to the[/color]
        >latter[color=green]
        >> innerHTML though. If they don't match, then it didn't work:[/color]
        >
        >You can also (safely, I think) assume that a value gotten from the
        >innerHTML property can be put back in and give the same result.[/color]

        Theoretically, and probably realistically, it should.
        [color=blue][color=green]
        >> function insertHTML(elem ,newHTML){
        >> tempVar = document.getEle mentById(elem). innerHTML;
        >> document.getEle mentById(elem). innerHTML = newHTML;
        >> if (tempVar == document.getEle mentById(elem). innerHTML) {alert('It[/color]
        >failed')}[color=green]
        >> }[/color]
        >
        >This only thsts the ability to change, not to change correctly :)
        >It is probably enough, but you can do a test like this;[/color]

        It is enough. The test is only to see if the browser supports changing the
        innerHTML, not to see whether it renders it correctly or not. Your test almost
        reminds me of the safecracker who wanted to use a nuclear bomb to open a safe
        s/he bought on Ebay.
        --
        Randy

        Comment

        • Jim Ley

          #49
          Re: Changing text between &lt;div&gt;' s

          On 03 Jan 2004 00:37:06 GMT, hikksnotathome@ aol.com (HikksNotAtHome )
          wrote:[color=blue]
          >Neither of which will match the original code. The only way to try to match
          >them is to check every known browser, see what it puts in the textarea, and
          >then do browser detection to try to find out what browser so you can determine
          >what string it should match.[/color]

          I was relying on the fact it would be a normalised source, so by
          putting in mixed case element names, and extra whitespace in the
          elements I was relying that if innerHTML wasn't known, then it would
          be the same (it would just be a new property on the DOM element) but
          it if it was known it was normalised away.

          Jim.
          --
          comp.lang.javas cript FAQ - http://jibbering.com/faq/

          Comment

          • Jim Ley

            #50
            Re: Changing text between &lt;div&gt;' s

            On Sat, 03 Jan 2004 01:59:25 +0100, Lasse Reichstein Nielsen
            <lrn@hotpop.com > wrote:
            [color=blue]
            >You can also (safely, I think) assume that a value gotten from the
            >innerHTML property can be put back in and give the same result.[/color]

            The same would be true of .chicken or a read only innerHTML that
            resulted in no change afterwards. What we want to know is if our
            content ended up on the page.

            Jim.
            --
            comp.lang.javas cript FAQ - http://jibbering.com/faq/

            Comment

            • Lasse Reichstein Nielsen

              #51
              Re: Changing text between &lt;div&gt;' s

              jim@jibbering.c om (Jim Ley) writes:
              [color=blue]
              > The same would be true of .chicken or a read only innerHTML that
              > resulted in no change afterwards. What we want to know is if our
              > content ended up on the page.[/color]

              Ah, Doh. *slaps forehead*. Yes, simply testing that you can write
              to it, is not sufficient.

              You assume that the HTML is normalized when passed through innerHTML.
              That is a fair assumption, and correct for the current browsers.

              Another method could be to create an element with an id, and then check
              whether it becomes part of the document with document.getEle mentById
              (or fallbacks, e.g., document.all, as usual).


              /L
              --
              Lasse Reichstein Nielsen - lrn@hotpop.com
              DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
              'Faith without judgement merely degrades the spirit divine.'

              Comment

              • HikksNotAtHome

                #52
                Re: Changing text between &lt;div&gt;' s

                In article <3ff6bd9b.41651 8@news.cis.dfn. de>, jim@jibbering.c om (Jim Ley)
                writes:
                [color=blue]
                >
                >I was relying on the fact it would be a normalised source, so by
                >putting in mixed case element names, and extra whitespace in the
                >elements I was relying that if innerHTML wasn't known, then it would
                >be the same (it would just be a new property on the DOM element) but
                >it if it was known it was normalised away.[/color]

                Just for my own curiosity, do you see any problems with the function I wrote to
                check to see if it works?

                function insertHTML(elem ,newHTML){
                tempVar = document.getEle mentById(elem). innerHTML;
                document.getEle mentById(elem). innerHTML = newHTML;
                if (tempVar == document.getEle mentById(elem). innerHTML) {alert('It failed')}
                }

                Maybe a different alert message (or another notifying mechanism). I left out
                the object detection that should obviously go with it though.
                --
                Randy

                Comment

                • Lasse Reichstein Nielsen

                  #53
                  Re: Changing text between &lt;div&gt;' s

                  hikksnotathome@ aol.com (HikksNotAtHome ) writes:
                  [color=blue]
                  > Just for my own curiosity, do you see any problems with the function
                  > I wrote to check to see if it works?[/color]

                  I can see the same problem he pointed out in my attempt :)
                  [color=blue]
                  > function insertHTML(elem ,newHTML){
                  > tempVar = document.getEle mentById(elem). innerHTML;
                  > document.getEle mentById(elem). innerHTML = newHTML;
                  > if (tempVar == document.getEle mentById(elem). innerHTML) {alert('It failed')}
                  > }[/color]

                  Change "innerHTML" to "chicken" and it appears to work. That is, it only
                  tests whether there is a writeable property, not whether assigning to it
                  changes the document structure.
                  It would succeede in Netscape 4, if the getElementById had worked.

                  /L
                  --
                  Lasse Reichstein Nielsen - lrn@hotpop.com
                  DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                  'Faith without judgement merely degrades the spirit divine.'

                  Comment

                  • Dr John Stockton

                    #54
                    Re: Changing text between &lt;div&gt;' s

                    JRS: In article <3ff6be1e.54710 6@news.cis.dfn. de>, seen in
                    news:comp.lang. javascript, Jim Ley <jim@jibbering. com> posted at Sat, 3
                    Jan 2004 13:07:02 :-[color=blue]
                    >On Sat, 03 Jan 2004 01:59:25 +0100, Lasse Reichstein Nielsen
                    ><lrn@hotpop.co m> wrote:
                    >[color=green]
                    >>You can also (safely, I think) assume that a value gotten from the
                    >>innerHTML property can be put back in and give the same result.[/color]
                    >
                    >The same would be true of .chicken or a read only innerHTML that
                    >resulted in no change afterwards. What we want to know is if our
                    >content ended up on the page.[/color]

                    We want to know if the previous visible content (if any) is removed, if
                    new content appears, and if new content looks as expected; or if an
                    error message appears.

                    We, as authors, can never know, since writing for an unknown browser is
                    a one-way process. Only if we can run the same version of the same
                    browser and test it ourselves can we really know.

                    Our code can never know all of the above; it cannot detect a fatal
                    error, it cannot read the screen, and it cannot detect a systematic
                    delusion that the required property is spelt InnerHTML.


                    ISTM that

                    <div ID=X><FONT color=red>NO GOOD</font></div>
                    That should read "All seems well", in lime.

                    <script ... >
                    DynWrite('X', '<FONT color=lime>All seems well</font>')

                    should enable the user to tell whether things are at least to some
                    extent working.

                    --
                    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                    <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
                    <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                    <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                    Comment

                    • HikksNotAtHome

                      #55
                      Re: Changing text between &lt;div&gt;' s

                      In article <isjsaaiu.fsf@h otpop.com>, Lasse Reichstein Nielsen <lrn@hotpop.com >
                      writes:
                      [color=blue]
                      >Change "innerHTML" to "chicken" and it appears to work. That is, it only
                      >tests whether there is a writeable property, not whether assigning to it
                      >changes the document structure.
                      >It would succeede in Netscape 4, if the getElementById had worked.[/color]

                      <sigh> CRAP! </sigh>

                      I knew I was missing something...... ...
                      --
                      Randy

                      Comment

                      • Dr John Stockton

                        #56
                        Re: Changing text between &lt;div&gt;' s

                        JRS: In article <20040103135907 .08626.00002478 @mb-m27.aol.com>, seen in
                        news:comp.lang. javascript, HikksNotAtHome <hikksnotathome @aol.com>
                        posted at Sat, 3 Jan 2004 18:59:07 :-
                        [color=blue]
                        >Just for my own curiosity, do you see any problems with the function I wrote to
                        >check to see if it works?
                        >
                        >function insertHTML(elem ,newHTML){
                        >tempVar = document.getEle mentById(elem). innerHTML;
                        >document.getEl ementById(elem) .innerHTML = newHTML;
                        >if (tempVar == document.getEle mentById(elem). innerHTML) {alert('It failed')}
                        >}[/color]

                        One needs also to check that it fails correctly!

                        Consider
                        insertHTML('F', 'OK')
                        insertHTML('F', 'OK')
                        The second one will report failure. A script could well have an error-
                        message Div, writing 'OK' or a fault-report to it for each iteration.

                        I get no alert on once executing a version of the above with innerHTML
                        changed to innnerHTML, which implies that the pre-existence of innerHTML
                        must be tested.

                        One might read the existing innerHTML, add a character to it, write it,
                        and read back; that seems OK even if innerHTML is undefined.

                        --
                        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                        <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
                        <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                        Comment

                        Working...