[Greasemonkey] newbie DOM question
Jeremy Dunck
jdunck at gmail.com
Wed Feb 1 12:22:31 EST 2006
On 2/1/06, Tod Beardsley <todb at planb-security.net> wrote:
> This doesn't work:
>
> Img.width = '90%'; So this doesn't work.
>
> This does:
> newDiv.innerHTML = "<img src="+ImgData+" width='90%' />";
>
> Any ideas why? I can use Img.width='100'; fine (makes it 100 pixels),
> just the percent makes it all go away.
I found that setting the width to a relative percentage after
appending the img node doesn't work either. (I did this because my
hunch was that 90% couldn't be evaluated without a parent node to
judge containment, since relative widths are "based on the horizontal
or vertical space currently available, not on the natural size of the
image" [1].)
I was about to say that it was a Firefox bug, but in fact, IE behaves
the same way.
When you use the innerHTML approach, the parent node is known, so the
available width is also known, meaning the actual size can be
calculated.
... Admittedly, the HTML DOM is pretty vaguely specified. Either I'm
being stupid, or this is an example of the real-world diverging from
the spec.
[1]
http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.7.1
More information about the Greasemonkey
mailing list