Closed Bug 262946 Opened 20 years ago Closed 19 years ago

Setting innerText field of Anchor object in JavaScript does not update the inner text

Categories

(Firefox :: General, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 254174

People

(Reporter: kahahn, Assigned: bugzilla)

Details

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; rv:1.7.3) Gecko/20041001 Firefox/0.10.1 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; rv:1.7.3) Gecko/20041001 Firefox/0.10.1 See JavaScript html below. This html does the expected under MSIE 5.x. That is, the "hey" text is replaced on loading with "This is good stuff": and on clicking the link it is replaced with "This is bad stuff:". Note that the alert lines are added to confirm the path that JavaScript took. When I run the same html under Firefox 1.0, the alerts indicate that the correct path was taken through the JavaScript code, but the innerText field does not update (it continues to say "hey" all the time). BTW the html below is based upon code found at the tutorial site: http://www.w3schools.com/js/tryit.asp?filename=try_dom_anchor_href The tutorial code you will find at that link has the same problem under Firefox 1.0. <html> <head> <script type="text/javascript"> <!-- var text1; var text2; function initPage() { text1 = "This is good stuff:"; text2 = "This is bad stuff:"; updatePage(0); } function updatePage(select) { switch (select) { case 0: document.getElementById('myAnchor').innerText=text1; alert(text1); break; case 1: document.getElementById('myAnchor').innerText=text2; alert(text2); break; } } //--> </script> </head> <body onload="initPage()"> <a name="this"> <p>Before span <a id="myAnchor" href="#this" onclick="updatePage(1)">hey</a> after span</p> </body> </html> Reproducible: Always Steps to Reproduce: 1. Run the html code given in the details (or the code pointed to by the URL given. 2. Compare how this html code behaves under Firefox and MSIE 3. Actual Results: See details: innerText fails to update. Expected Results: innerText should update the same way it does for MSIE
Gecko (and thus both Mozilla and Firefox) doesn't support IE's proprietary innerText property. See http://www.mozilla.org/docs/web-developer/upgrade_2.html#dom_unsupp DOM Level 3's textContent property is supported, though, so a cross-browser script is easy enough to do: var elem = document.getElementById('myAnchor'); switch (select) { case 0: elem.textContent ? elem.textContent=text1 : elem.innerText=text1;
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → INVALID
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
*** This bug has been marked as a duplicate of 254174 ***
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago19 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.