tlendz@gmail.com wrote :
Quote:
Hi,
>
I've got several divs with the same id/name,
That's invalid. id must be document-unique.
Quote:
and text inside (font-
family:georgia,serif), and would like the users to be able to change
the font, in case they don't like the default one.
They can do this with their browser preferences too. Why do you need to
code this for them? At the very least, you would be better with
alternate stylesheets.
I have come up with
Quote:
this code, however it updates the divs' style only once, to 'arial',
whereas I would like them to be switched to 'times new roman',
'verdana', back to 'georgia', and so on. All with consecutive click on
a single link:
>
<a href="javascript
:fontnew();\>Change Font</a>>
"javascript
:" pseudo-links become dysfunctional when javascript support
is disabled or inexistent.
"javascript
:" links will interfere with advanced features in tab-capable
browsers: eg. middle-click on links, Ctrl+click on links, tab-browsing
features in extensions, etc.
"javascript
:" links will interfere with the process of indexing webpages
by search engines.
"javascript
:" links interfere with assistive technologies (e.g. voice
browsers) and several web-aware applications (e.g. PDAs and mobile
browsers).
"javascript
:" links also interfere with "mouse gestures" features
implemented in browsers.
Protocol scheme "javascript
:" will be reported as an error by link
validators and link checkers.
http://jibbering.com/faq/#FAQ4_24 Quote:
>
function fontnew() {
var div;
var newfamily;
newfamily is declared and created locally; the scope of newfamily is
local, not global here.
Quote:
if (!done) { var done; }
done is declared locally and created locally.
Quote:
done = 0;
if (!newfamily) { newfamily = 'georgia,serif'; }
The above instruction is bound to be created and recreated at each call
of fontnew().
Quote:
>
if (done==0 && newfamily == 'georgia,serif') { newfamily = 'arial';
done = 1; }
if (done==0 && newfamily == 'arial') { newfamily = 'times new roman';
Times new roman must be quoted in valid CSS since it has blank spaces.
Font names containing any whitespace should be quoted according to CSS 2.x
Quote:
done = 1; }
if (done==0 && newfamily == 'times new roman') { newfamily =
'verdana'; done = 1; }
if (done==0 && newfamily == 'verdana') { newfamily ==
'georgia,serif'; done = 1; }
var divs = document.getElementsByName('M');
<div>s can not have names; that's invalid markup code. If all divs are
to change their font-family, then you don't need to assess them id or
name or classes: just iterate them all or just set the font-family to
their top wrapping element within the containment hierarchy. What you do
or try to do is not efficient and frankly not recommendable. Defining
an alternate stylesheet makes a lot more sense.
Quote:
for (i = 0; i < divs.length; i++) {
div = divs[i];
div.style.fontFamily = newfamily;
}
}
Gérard
--
Using Web Standards in your Web Pages (Updated Dec. 2006)
http://developer.mozilla.org/en/docs...your_Web_Pages