troubleshooting Question

jquery, difference between text() and html()

Avatar of elepil
elepil asked on
JavaScriptjQuery
18 Comments1 Solution140 ViewsLast Modified:
Let me qualify my question. I know the difference between text() and html() when WRITING in that text() outputs ascii as text, while html() will output ascii as html (as demonstrated by the FIRST brief sample. My question is in READING (see the SECOND example).

<html>
<head>
  <title>Test Page</title>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  <script type="text/javascript">
    $(function(){
      $("#div1").html('<a href="example.html">Link</a><b>hello</b>');
      $("#div2").text('<a href="example.html">Link</a><b>hello</b>');
    });
  </script>
</head>

<body>

<div id="div1"></div>
<div id="div2"></div>

</body>
</html>

This next sample attempts to READ the text() and html() and simply outputs the values to the <result1> and <result2> tags:

<html>
<head>
  <title>Test Page</title>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  <script type="text/javascript">
    $(function(){
		$("result1").html($("#div1").html());
		$("result2").html($("#div1").text());
    });
  </script>
</head>

<body>

<div id="div1">This is div1</div><p/>

<result1></result1><br/>
<result2></result2>

</body>
</html>

They look the same visually, but I know they're internally not. And I know that because of this actual example I was playing around with (which looks long but really isn't, it's just a bunch of "lorem ipsum" text. All I'm trying to do is look for all <h3> tags and make bookmark links out of them. Look for my comments very near the beginning, all in UPPER CASE where I show the actual line I'm have a question on:

<!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">
<head>
    <title>Creating Automatic Bookmarks</title>
    <script type="text/javascript" src="../jquery-1.9.1.js"></script>
    <script type="text/javascript">
        $("document").ready(function() {
            buildBookmarks('h3', 'header');
        });

        function buildBookmarks(strWhichTag, sBookMarkNode) {
            var cAnchorCount = 0;

            // create the list that will hold the bookmark links
            var oList = $("<ul id='bookmarksList'>");

            // for each one of the header tags, create a new named anchor and insert it into
            // the header tag. Then add a new link to the list that points to the named anchor
            $(strWhichTag).each(function() {
                $(this).html("<a name='bookmark" + cAnchorCount + "'></a>" + $(this).html());
/***********HERE IS MY COMMENT
IN THE NEXT LINE, IF YOU REPLACE $(this.text() WITH $(this).html(), THE TEXT WILL NO LONGER APPEAR AS HYPERLINKS. SO CLEARLY, THERE IS A DIFFERENCE BETWEEN text() AND html(), EVEN THOUGH THEY LOOK IDENTICAL WHEN OUTPUT TO THE SCREEN, AND I WANT TO UNDERSTAND WHAT'S GOING ON BEHIND THE SCENES.
***********************/
                oList.append($("<li><a href='#bookmark" + cAnchorCount++ + "'> " + $(this).text() + "</a></li>"));
            });

            // now find the ID of the bookmark container and append it
            $("#" + sBookMarkNode).append(oList);
        }
    </script>
</head>
<body>
    <div id="header">
        <h1>
            Automatic Bookmark Headings Example</h1>
        <h2>
            Using jQuery to Extract Existing Page Information</h2>
        <p id="byline">&nbsp;</p>
    </div>
    <div id="intro">
        <h3>
            Introduction</h3>
        <p>
            Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
            tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero
            eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea
            takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur
            sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna
            aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
            ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor
            sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
            eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
        </p>
        <p>
            Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat,
            vel illum dolore eu feugiat nulla facilisis. At vero eos et accusam et justo duo
            dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem
            ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
            diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed
            diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
            kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum
            dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore
            dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet
            clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua.
            est Lorem ipsum dolor sit amet.
        </p>
        <p>
            Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
            tempor invidunt ut labore et dolore magna aliquyam erat. Consetetur sadipscing elitr,
            sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
            sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
            clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
            ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
            invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
        </p>
        <a href="#header" title="return to the top of the page">Back to top</a>
    </div>
    <div id="ingredients">
        <h3>
            At Vero Eos et Accusam et Justo Duo Dolores</h3>
        <p>
            At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
            no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure
            dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore
            eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui
            blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
            euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad
            minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip
            ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate
            velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero
            eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit
            augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend
            option congue nihil imperdiet doming id quod mazim placerat facer possim assum.
            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
            euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad
            minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip
            ex ea commodo consequat.
        </p>
        <p>
            Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
            tempor invidunt ut labore et dolore magna aliquyam erat. Consetetur sadipscing elitr,
            sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
            sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
            clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
            ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
            invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
        </p>
        <p>
            Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
            tempor invidunt ut labore et dolore magna aliquyam erat. Consetetur sadipscing elitr,
            sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
            sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
            clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
            ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
            invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
        </p>
        <a href="#header" title="return to the top of the page">Back to top</a>
    </div>
    <div id="prepare">
        <h3>
            Lorem Ipsum Dolor sit Amet</h3>
        <p>
            Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat,
            vel illum dolore eu feugiat nulla facilisis. At vero eos et accusam et justo duo
            dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem
            ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
            diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed
            diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
            kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum
            dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore
            dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet
            clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua.
            est Lorem ipsum dolor sit amet.
        </p>
        <p>
            Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
            tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero
            eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea
            takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur
            sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna
            aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
            ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor
            sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
            eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
        </p>
        <pre>  function hideDivs()
  {
    var divs = document.getElementsByTagName(&#34;div&#34;);
    for(var i=0; i &#60; divs.length; i++)
    {
      var div = divs[i];
      var id = div.id;
      if ((id != &#34;header&#34;) &#38;&#38;
          (id != &#34;footer&#34;))
      {
        div.style.display = &#34;none&#34;;
      }
    }
  }

  window.onload = function()
  {
    hideDivs();
  }</pre>
        <p>
            Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
            tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero
            eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea
            takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur
            sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna
            aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
            ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor
            sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
            eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
        </p>
        <pre>  if (!document.getElementsByTagName) return null;</pre>
        <p>
            At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
            no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure
            dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore
            eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui
            blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
            euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad
            minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip
            ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate
            velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero
            eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit
            augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend
            option congue nihil imperdiet doming id quod mazim placerat facer possim assum.
            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
            euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad
            minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip
            ex ea commodo consequat.
        </p>
        <pre>  function hideDivs(<strong>exempt</strong>)
  {
    if (!document.getElementsByTagName) return null;
    <strong>if (!exempt) exempt = &#34;&#34;;</strong>
    var divs = document.getElementsByTagName(&#34;div&#34;);
    for(var i=0; i &#60; divs.length; i++)
    {
      var div = divs[i];
      var id = div.id;
      if ((id != &#34;header&#34;) &#38;&#38;
          (id != &#34;footer&#34;) <strong>&#38;&#38; (id != exempt)</strong>)
      {
        div.style.display = &#34;none&#34;;
      }
    }
  }

  window.onload = function()
  {
    hideDivs(<strong>&#34;intro&#34;</strong>);
  }</pre>
        <p>
            Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
            tempor invidunt ut labore et dolore magna aliquyam erat. Consetetur sadipscing elitr,
            sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
            sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
            clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
            ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
            invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
        </p>
        <pre>  function fixLinks()
  {
    if (!document.getElementsByTagName) return null;
    var anchors = document.getElementsByTagName(&#34;a&#34;);
    for(var i=0; i &#60; anchors.length; i++)
    {
      var a = anchors[i];
      var href = a.href;
      if ((href.indexOf(&#34;#&#34;) != -1) &#38;&#38;
          (href.indexOf(&#34;header&#34;) == -1))
      {
        var index = href.indexOf(&#34;#&#34;) + 1;
        href = &#34;javascript:show('&#34; +
               href.substring(index) + &#34;');&#34;;
        a.setAttribute(&#34;href&#34;,href);
      }
    }
  }</pre>
        Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat,
        vel illum dolore eu feugiat nulla facilisis. At vero eos et accusam et justo duo
        dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem
        ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
        diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed
        diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
        kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
        <br />
        <p>
            Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat,
            vel illum dolore eu feugiat nulla facilisis. At vero eos et accusam et justo duo
            dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem
            ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
            diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed
            diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
            kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Now, about
            that <code>show</code> function&#8230; This is a simple function that uses the <acronym
                title="Document Object Model">DOM</acronym> to show an identified node and hide
            the rest. We already have a great multi-purpose hiding function in <code>hideDivs</code>,
            so all we need is the &#8220;show&#8221; part. Here&#8217;s the code:</p>
        <pre>  function show(what)
  {
    if (!document.getElementById) return null;
    showWhat = document.getElementById(what);
    showWhat.style.display = &#34;block&#34;;
    hideDivs(what);
  }</pre>
        <p>
            At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
            no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure
            dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore
            eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui
            blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
            euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad
            minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip
            ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate
            velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero
            eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit
            augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend
            option congue nihil imperdiet doming id quod mazim placerat facer possim assum.
            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
            euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad
            minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip
            ex ea commodo consequat.
        </p>
        <a href="#header" title="return to the top of the page">Back to top</a>
    </div>
    <div id="decorate">
        <h3>
            Stet Clita Kasd Gubergren</h3>
        <p>
            At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
            no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure
            dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore
            eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui
            blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
            euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad
            minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip
            ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate
            velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero
            eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit
            augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend
            option congue nihil imperdiet doming id quod mazim placerat facer possim assum.
            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
            euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad
            minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip
            ex ea commodo consequat.
        </p>
        <pre>  function hideDivs(exempt)
  {
    if (!document.getElementsByTagName) return null;
    if (!exempt) exempt = &#34;&#34;;
    var divs = document.getElementsByTagName(&#34;div&#34;);
    for(var i=0; i &#60; divs.length; i++)
    {
      var div = divs[i];
      var id = div.id;
      if ((id != &#34;header&#34;) &#38;&#38;
          (id != &#34;footer&#34;) &#38;&#38;
          (id != exempt))
      {
        <strong>div.className = &#34;hidden&#34;;</strong>
      }
    }
  }

  function show(what)
  {
    if (!document.getElementById) return null;
    showWhat = document.getElementById(what);
    <strong>showWhat.className = &#34;&#34;;</strong>
    hideDivs(what);
  }

  window.onload = function()
  {
    hideDivs("intro");
    fixLinks();
  }</pre>
        <p>
            At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
            no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure
            dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore
            eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui
            blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
            euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad
            minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip
            ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate
            velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero
            eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit
            augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend
            option congue nihil imperdiet doming id quod mazim placerat facer possim assum.
            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
            euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad
            minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip
            ex ea commodo consequat.
        </p>
        <pre>  function fixLinks()
  {
    if (!document.getElementsByTagName) return null;
    var anchors = document.getElementsByTagName(&#34;a&#34;);
    for(var i=0; i &#60; anchors.length; i++)
    {
      var a = anchors[i];
      var href = a.href;
      <strong>if (href.indexOf("#header") != -1) { a.className = "alt"; } else </strong>if ((href.indexOf(&#34;#&#34;) != -1) &#38;&#38;
                  (href.indexOf(&#34;header&#34;) == -1))
      {
        var index = href.indexOf(&#34;#&#34;) + 1;
        href = &#34;javascript:show('&#34; +
               href.substring(index) + &#34;');&#34;;
        a.setAttribute(&#34;href&#34;,href);
      }
    }
  }</pre>
        <p>
            Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
            tempor invidunt ut labore et dolore magna aliquyam erat.
        </p>
        <pre>  .alt {
    display: none;
  }</pre>
        <a href="#header" title="return to the top of the page">Back to top</a>
    </div>
    <div id="serve">
        <h3>
            Tempor Invidunt ut Labore et Dolore
        </h3>
        <p>
            Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
            tempor invidunt ut labore et dolore magna aliquyam erat. Consetetur sadipscing elitr,
            sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
            sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
            clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
            ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
            invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
        </p>
    </div>
</body>
</html>
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 18 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 18 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros