Closed Bug 62337 Opened 24 years ago Closed 24 years ago

innerHTML misrepresents style attributes

Categories

(Core :: DOM: CSS Object Model, defect, P3)

defect

Tracking

()

VERIFIED FIXED
mozilla0.9

People

(Reporter: wo, Assigned: jst)

Details

(Whiteboard: [HAVE FIX])

Attachments

(2 files)

The innerHTML property of an element does not correctly display the HTML content of the element: <div id="element1"> <div id="element2" style="color:red">text in element2</div> </div> Calling alert(document.getElementById("element1").innerHTML) will now show: <div id="element2" style="element2color: red; ">text in element2</div> Two things are wrong with that: - the element id reappears in the style value. - white spaces and semicolons are inserted in the style value. This happens with M0.6 on win98.
There's nothing wrong with adding the whitespace and the semicolon to the attribute value since that's only a normalized version of the style rule, it still has the exact same meaning. The fact that the id attribute value appears in the style attribute seems weird and is wrong, could you attach a testcase to this bug that demonstrates what you stated above? Thanks!
Attached file testcase
Thanks for the testcase! I found the problem, fixing it is a one liner in nsGenericHTMLElement.cpp Index: html/content/src/nsGenericHTMLElement.cpp =================================================================== RCS file: /cvsroot/mozilla/layout/html/content/src/nsGenericHTMLElement.cpp,v retrieving revision 1.221 diff -u -r1.221 nsGenericHTMLElement.cpp --- nsGenericHTMLElement.cpp 2000/11/27 07:54:37 1.221 +++ nsGenericHTMLElement.cpp 2000/12/09 02:36:58 @@ -1726,14 +1627,16 @@ nsGenericHTMLElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute, nsAWritableString& aResult) const { + aResult.SetLength(0); + #if 0 Note, line numbers may wary... I'll land this fix with my content model cleanup landing that will hopefully happen next week. If this isn't marked fixed in a week please remind me about it.
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
OS: Windows 98 → All
Hardware: PC → All
Whiteboard: [HAVE FIX]
Target Milestone: --- → mozilla0.9
herewith I remind you. :)
Thanks! Unfortunately I wasn't able to get my changes in yet, hopefully this week, feel free to remind me again in a week-or-so :-)
CC'ing self. Johnny, I'm seeing a problem that when I use innerHTML, the style of the HTML element is completely ignored. For example if I use the following: document.getElementById("hello").innerHTML = "<INPUT type=\"text\" style=\"color: green\" value=\"foo2\">"; the color is completely ignored (along with every other style element). Will landing your changes fix this or should I log another bug? I'll upload my testcase so you can take a look at it as well. Thanks David
drat, sorry for the spam. I'm using mozilla build 2001010306 on Linux 2.2.
The changes that included my fix for this landed a few weeks ago, marking FIXED. djoham, the problem you found is unrelated to this bug, please open a new DOM bug on that problem.
Really marking fixed this time.
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
Component: DOM Level 2 → DOM Style
Taking QA Contact on all open or unverified DOM Style bugs...
QA Contact: vidur → ian
testcases appear to work now
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: