Thanks IA, Simon
Simon wrote:
Well, with the W3C DOM as implemented in IE5+, Netscape 6+, Opera 7 you
can access any element by its id attribute e.g.
<span id="aSpan">Kibology</span>
then you can script
var span;
if (document.getElementById) {
span = document.getElementById('aSpan');
if (span) {
// use span here e.g.
// span.style.backgroundColor = 'lightblue';
}
}
As for accessing the span's content the easiest cross browser way is
probably
span.innerHTML
though the DOM in IE5+ and Opera 7 also provides
span.innerText
and the W3C DOM has several ways of accessing child nodes
--
Martin Honnen
http://JavaScript.FAQTs.com/
[snip]
> As for accessing the span's content the easiest cross browser way is
> probably
> span.innerHTML
Is that a cross-browser approach? I don't believe it is. It's just another
Microsoft invention that just happens to be implemented by the major
players in browser development. It hasn't been published in any standard
to date.
Mike
--
Michael Winter
M.Wi...@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Michael Winter wrote:
> On Thu, 11 Mar 2004 14:42:43 +0100, Martin Honnen <maho...@yahoo.de>
> wrote:
>> As for accessing the span's content the easiest cross browser way is
>> probably
>> span.innerHTML
>
>
> Is that a cross-browser approach? I don't believe it is. It's just
> another Microsoft invention that just happens to be implemented by the
> major players in browser development. It hasn't been published in any
> standard to date.
Well,
var img = new Image();
img.src = 'whatever.gif';
is a cross browser approach of preloading an image without being
published in any standard either so I don't know how a standard helps.
We have SVG 1.0 and SVG 1.1 standards which doesn't mean you can serve
SVG to major browsers and they handle it just because it is a standard.
My post mentioned browsers for which innerHTML is a cross browser approach.
[snip]
> Well,
> var img = new Image();
> img.src = 'whatever.gif';
> is a cross browser approach of preloading an image without being
> published in any standard either so I don't know how a standard helps.
> We have SVG 1.0 and SVG 1.1 standards which doesn't mean you can serve
> SVG to major browsers and they handle it just because it is a standard.
That is a very good point, as exemplified by IE with...well most standards.
Don't get me wrong. I'm not trying to imply that standards are a way of
guaranteeing implementation. If that were the case, once a new standard is
released, you wouldn't need to write fallbacks for modern browsers. This
doesn't happen though. Even after the three years since DOM 2 Style was
released, Opera[1] still doesn't implement the styleSheets collection.
However, I would argue that it's misleading to rate a proprietory feature
as cross-browser as opposed to the equivalent W3C DOM approach, which is
more likely to be supported over a wider range of browsers.
> My post mentioned browsers for which innerHTML is a cross browser
> approach.
I read that as examples of browsers that supported the getElementById()
method, actually.
Mike
[1] I thought I'd give Microsoft a break, for a change.
The proprietary innerHTML property has an unusual place in cross-browser
scripting because the modern dynamic browsers; IE, Mozilla/Gecko,
Safari/Konqueror, Opera and IceBrowser, all implement it dynamically in
addition to (sufficient) W3C DOM methods. So with IE 4 implementing
innerHTML but no W3C DOM methods the numbers stack up in favour of
innerHTML as the most cross-browser method of modifying DOM structure
and page contents.
The browsers that do not implement innerHTML but do implement some of
the W3C DOM methods (e.g. Opera 5 & 6, NetFront/Web Browser 2) tend not
to be dynamic so modifying the DOM or contents is not an option there
anyway.
But with a browser's javascript support not being sufficient to infer
the ability to dynamically modify the DOM' structure the problem with
either approach is matching the desire to use one of the techniques with
the browsers support for the feature.
<snip>
> [1] I thought I'd give Microsoft a break, for a change.
Haven't Microsoft been on a break from browser development for nearly
two years now? I think it is probably time they got back to it. ;-)
Richard.
> Haven't Microsoft been on a break from browser development for nearly
> two years now? I think it is probably time they got back to it. ;-)
I strongly disagree with that. The release of IE 7 will be a very dark
day indeed. Microsoft's greatest service to the stability of the web has
been to not introduce new bugs and incompatibilities for two years.
Considering their history, this has been a significant accomplishment
for them. I would like very much for this to continue.
Bravo, Microsoft. Keep it not coming. No new bugs.
LOL. The glass is half full; that is one way of looking at it.
Richard.
Probably should have mentioned that I have no control over the page content
so no idea of names/ids.
> As for accessing the span's content the easiest cross browser way is
> probably
> span.innerHTML
> though the DOM in IE5+ and Opera 7 also provides
> span.innerText
> and the W3C DOM has several ways of accessing child nodes
> --
Thanks for that Martin. I found the most effective way to look through an
unknown page's elements is using document.links, document.forms[x].children
and document.body.children. Seems to work for all the elements on the pages
I use so far.
Simon
!mran Khan
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Simon wrote:
>> if (document.getElementById) {
>> span = document.getElementById('aSpan');
>
> Probably should have mentioned that I have no control over the page content
> so no idea of names/ids.
Then you can't find elements by id but the DOM offers other ways,
var spans = document.getElementsByTagName('span');
that yields a collection with all <span> elements in the document with
IE5+, Netscape 6+, Opera 6+.
>>As for accessing the span's content the easiest cross browser way is
>>probably
>> span.innerHTML
>>though the DOM in IE5+ and Opera 7 also provides
>> span.innerText
>>and the W3C DOM has several ways of accessing child nodes
>>--
>
>
> Thanks for that Martin. I found the most effective way to look through an
> unknown page's elements is using document.links, document.forms[x].children
> and document.body.children. Seems to work for all the elements on the pages
> I use so far.
No, forget about children, that is IE only, if you want to write cross
browser code use
document.getElementsByTagName('tagname')
element.getElementsByTagName('tagname')
and
node.childNodes
And then wonder why it only works in IE? .innerText is IE-only.
innerHTML is at least more cross-browser.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Thanks - I use getElementsByTagName now and it works just fine.