Re: Script for Hiding/Un-Hiding Text On Click



On Jul 23, 8:41 pm, Randy Webb <HikksNotAtH...@xxxxxxx> wrote:
David Mark said the following on 7/23/2007 7:16 PM:

On Jul 23, 6:16 pm, Randy Webb <HikksNotAtH...@xxxxxxx> wrote:
David Mark said the following on 7/23/2007 2:08 PM:
On Jul 23, 12:56 am, Randy Webb <HikksNotAtH...@xxxxxxx> wrote:
David Mark said the following on 7/22/2007 7:36 PM:
On Jul 22, 6:37 pm, Randy Webb <HikksNotAtH...@xxxxxxx> wrote:
David Mark said the following on 7/22/2007 6:20 PM:
On Jul 21, 8:18 pm, ASM <stephanemoriaux.NoAd...@xxxxxxxxxxxxxxxxxx>
wrote:

<snip>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>FAQ</title>
<script type="text/javascript">
if (document.getElementById) document.write('<style type="text/
css">#questions dd {display:none}<\/style>');
That is a preposterously inept test. I would think that a test for the
Not true. If document.getElementById is not supported then you don't
want to write this style. See below.
Again, you missed the point. You don't want that CSS written if:
a) You can't get a reference to the element (getElementById)
Yep.
b) You can't change the style property of that element.
There's no reliable way to know that. So nobody tests for that. Name
one browser that supports getElementById, but cannot change style
properties.
Sure there is. See my code at the bottom.

Not even the supposition that gEBI is present and that the style
property is present will assure you that you can change it.
Again, name one agent. Just one. Alternatively, post a code example
that tests for this occasion.
You are thinking backwards. Your attitude is "Until someone names one, I
don't have to worry about it". Mine is, if I code against that
possibility, I don't have to worry about it. One is a flawed attitude to
have.

No, I don't think you have a clue what my attitude is. I simply left
the further improvement of the example as an exercise. Do whatever
you want with it.

Your coding style - and the defense of it - says a lot about your
attitude about browser scripting. And the lack in your abilities of
successfully doing so.

Since you haven't posted any code at all, except for a botched re-hash
of mine, I don't think you have much to say on this subject.


<snip>

No test here to see if the browser supports gEBI or not?
if (el) {
var links = el.getElementsByTagName('a');
What makes you sure the browser supports getElementsByTagName?
What browser supports getElementById, but not getElementsByTagName?
If you can come up with one, then there should be two feature tests
before writing the style and attaching the onload handler.
And you think that is a better position than testing for it and not
caring if a browser doesn't support it? One way the browser silently
degrades, the other way it doesn't - it throws an error. Which is more
user friendly?
There just aren't any agents out there that support one and not the
other. But it isn't hard to add a test for getElementsByClassName if
you are worried about that. I'll leave that as an exercise.
I hope your "libraries" aren't riddled with that thought process. If
they are, then it is a good thing we haven't seen any of them.

What "libraries?" I think I mentioned one specific library in another
thread. Is that what you are talking about? If so, your hopes about
it are not of any concern as you don't use XHTML. I don't see how it
is either good or bad that you (and the mouse in your pocket) haven't
seen it.

It is your claim - in that "other thread" - that your code works
flawlessly whether the browser interprets the code as HTML or XHTML so

Applications I have written for both are working for both. What does
that have to do with this thread?

your claim that I don't use XHMTL (which is wrong in itself) is no
defense at all. Does your local college offer a class in public debate?

Defense of what?

If so, you should take it as you suck at it.

Never you mind what I should take.


<snip>
So no, your code doesn't come close to being a "preferable" solution. It
Preferable is relative.
may be better than what was posted.....
See the previous sentence. And by "may be", I assume you did compare
it to the previous post. So what exactly are you saying? Other than
the point about detecting getElementById, what would you suggest to
improve it?
I didn't claim the previous post was perfection. But tell me this
isn't:
OK, it isn't. Make you feel better? Whether I think it is or not, I
simply said it because you wanted me to. But no, it isn't. Not even
close because you still haven't realized the problem with this testing:
<snip>
if (document.getElementById) document.write('<style type="text/
css">#questions dd {display:none}<\/style>');
There you go again. That test makes no sense on its own. But paired
with the identical test a few lines down, it makes perfect sense.
No, the test is moronic whether it is duplicated or not. The style

Either you don't get it or you are trying to turn this discussion into
a personal attack. I don't really care either way as I am about ready
to stop reading your posts entirely.

It has nothing to do with being personal or not, the test for
document.getElementById is moronic if you think it satisfies the
requirement for knowing whether to write the style block or not.

You still don't get that do you?


element isn't even needed in the page at all for a modern browser. Even

What in God's name are you babbling about now? The style element
isn't needed for a modern browser? What does that mean?

It means precisely what I wrote. Can you not read plain English? The
style element doesn't have to be written for a "modern browser". Any of
the modern browsers don't need it there in order to manipulate the styles.

Which has nothing at all to do with why I wrote it.


if it is (I think IE6 didn't like manipulating styles that weren't
defined)

You think wrong.

Ok. I didn't really care at the time as it was irrelevant to me.

So it is okay to post nonsense as long as it isn't relevant to you?


it would be hard coded as display: block. See below.

Hard coded? display: block? That's the default!

You really are as inept as I thought you were. It may have been IE5.0,
IE5.5 I don't remember but it wouldn't allow you to modify a style if it
was not hard coded into the page. The way the code I wrote is written if
the browser couldn't modify it without it being hard coded then you
would have to hard code it. And to be able to - successfully -

This is "plain English?"

manipulate it then you would hard code it and the only way to hard code
it to make it gracefully degrade would be to code it as display: block.

Which you didn't do in your example. Yes, this is all quite clear.

The fact that you know nothing about that speaks volumes.

You are very hard to follow.


<snip>

if (document.getElementById) window.onload = windowLoad
That test - once again - is fatally flawed. Reread the post to figure
out why.
I don't have to re-read anything. You just keep repeating the same
thing as if I don't understand and that is a silly thing to do.
No, this isn't my first rodeo.
Odd that at the end of the day, you haven't posted a single line of
code. Where's the "if styles can be changed" feature test? It
obviously is just a theoretical waste of time.
It is? You get brownie points if you can correctly answer the last
question in this code:

You seem to be confused. Lets see how you did on your assignment to
improve my code. By the way, it took you long enough to complete.

The only one confused on how to write cross-browser degrading code is
you. Also, it was not an "assignment" (I will leave those for your
instructor to give you), it was proof of concept to show you how inept
you are at what you claim to do for a living.

LOL. I never claimed anything about what I do for a living. Cite one
post. Inept is thinking that the length of "000" is 1. Want me to
cite that one, professor? I suspect you are still smarting from it
and that explains your attitude.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd";>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>FAQ</title>
<script type="text/javascript">

function showAnswer() {
var id = this.id;
var el = document.getElementById('a' + id.substring(1));
if (el) el.style.display = (el.style.display == 'block')?'none':'block';
return false}

function windowLoad() {
var el = document.getElementById('questions')
if (el &&
el.getElementsByTagName &&
el.getElementsByTagName('a') &&
el.getElementsByTagName('dd') )
{
var links = el.getElementsByTagName('a');
var answers = el.getElementsByTagName('dd')
for (var i = links.length - 1; i >= 0; i--)
{
links[i].onclick = showAnswer;
links[i].href = '#';

If you are going to copy my code, at least copy the last version
posted.

I didn't copy "code", I copied some garbage text and modified it. There
is a difference but I doubt you would understand the difference.

links[i].tabIndex = 0;
if (answers[i].style)
{
answers[i].style.display = "none";

This is hardly an improvement. What you've done is make the answers
flash for a second during the page load. Furthermore, you now have
links that don't do anything if this assignment does not update the
screen (in whatever fantasy user agent you are "defending" against.)

The difference is that mine degrades, yours doesn't.

BTW, that "fantasy user agent" you keep alluding to is my cell phone
browser that supports gEBI but does not support modifying display
properties nor does it support getElementsByClassName. I know, I know,
you can't be bothered to support such devices as you don't know how.

}
}
}}

window.onload = windowLoad

Wrong. See below.

The only person wrong here is you. You just fail to see it is all.

</script>
</head>
<body>
<dl id="questions">
<dt><a id="q1">Q. Why isn't there a style element in the source code of
this page?</a></dt>
<dd id="a1">A. It isn't needed as the styles are only set if the browser
can set it.</dd>
<dt><a id="q2">Q. What happens if the browser can't set them?</a></dt>
<dd id="a2">A. Then the answers stay visible for fallback.</dd>
<dt><a id="q3">Q. Why won't the space far activate the links?</a></dt>
<dd id="a3">A. That is a damn good question.</dd>

No it isn't. What makes you think the space bar activates links?

Because that is precisely how I have to activate links in that "Fantasy
User Agent" you don't know how to support. The lower left key (*)
activates the "Enter key" functionality. The lower right key (#)
activates the "Space Bar" functionality and the only way to activate a
link with it is the space bar. Of which it does just fine with hard
coded links, just not dynamically created links.

"Your" example creates dynamic links just like mine. Not surprising
as it is basically mine with a couple of minor modifications.


Try the enter key.

See above.

See above.


<dt><a id="q4">Q. Why is this solution better?</a></dt>
<dd id="a4">A. It degrades better than the previous version.</dd>

Degrades better for browsers that don't exist, but is far uglier for
many browsers that do exist. I don't like it.

Try again moron. The code you posted is utterly broken in the "Fantasy
User Agent" I keep telling you about but the code I posted works
flawlessly in it.

And worse in IE, Opera, etc. And why can't you name the device? I
suspect it is an old cell phone from a garage sale. Did you test with
Netscape 4 too?


<dt><a id="q5">Q. Why is there no test for gEBI on the window.onload
call?</a></dt>
<dd id="a5">A. Because whether gEBI is present or not is irrelevant
there.</dd>

You didn't test for it anywhere, which is obviously incorrect. The
very first line of windowLoad attempts to use the getElementById
method. (!)

Awww man, now I gotta get depressed, you have a point.

Yes. All of that bluster and your code has a worse flaw than mine.


<dt><a id="q6">Q. What happens if there is no display property of the
style elemnt?</a></dt>

I assume you meant "display property of the style object."

Yes.

You'll notice I didn't insult you for the obvious gaffe. You should
take a page out of my book. Nobody respects a wise-ass.


<dd id="a6">A. Then it assigns it a new property and leaves the answers
visible. Change it to "chicken" to see it fall through gracefully.</dd>
<dt><a id="q7">Q. Are there any other flaws in this code?</a></dt>

Yes. And apparently in your personality too.

The only flaw in my "personality" is that I think I can educate idiots
like you. Sue me for it.

There you go again. Sue you for what? I doubt you have anything I
would want.


<dd id="a7">A. Yes. Can you, as a "programmer" tell me what they are?</dd>

Can you as a "jackass" try to understand that this thread is not a
contest?

Is that as original a name as you can call me? I have been called worse

The most fitting. And this isn't a name-calling contest any more than
it is a coding contest.

by a lot better than you. You have mistakenly assumed it was a
"contest". It isn't. It was my failed attempt to educate you as to the
flaws in your code.

Your series of posts here seem to exist only to impress me.

Keep dreaming moron.

How many times have you used that word in this thread? You only
degrade yourself.


I'm not impressed with the noisy buildup and the "payoff" turned out
to be a flawed fizzle. What a waste of time.

Yes, but not for the reasons you think. It was a waste of time on my
part to try to educate your dumb ass. Maybe someone in the future that
reads it can learn from it as you obviously can't.

"Dumb ass", "moron", etc., etc. You are stuck in a parochial rut.


I couldn't be so lucky as to not have you read my posts though as then I
could correct your non-sense babbling without having to waste my time
trying to educate you.

In English, please.

Never mind. We're done talking here.

.



Relevant Pages

  • Re: Script for Hiding/Un-Hiding Text On Click
    ... one browser that supports getElementById, ... attitude about browser scripting. ... var links = el.getElementsByTagName; ... There just aren't any agents out there that support one and not the ...
    (comp.lang.javascript)
  • Re: Critique this div resizing script
    ... You are assuming, falsely so, that the browser will support .style and ... .height just because it supports getElementById. ... Feature test before ...
    (comp.lang.javascript)
  • Re: "The Good Enough Revolution" - As it applies to js
    ... VB programs must be re-written because the current libraries don't ... I don't think MS needs to be singled out for poor support of web ... unknown browsers and until its adoption of feature testing, jQuery was ... All that needs to be anticipated is that a browser may not support any ...
    (comp.lang.javascript)
  • Re: Legacy code/browser compatibility
    ... excuse for never learning what could be achieved by hiding ... "How old must a browser be before you stop worrying about it? ... has ventured way off topic into fallback form/basic HTML support, ... Fall back may be for when javascript is unavailable but on ...
    (comp.lang.javascript)
  • Re: OT: browser hostile sites
    ... The last one is so bad that only powerstrip shutdown is possible. ... Either an older version or browser that doesn't support the newer web ... I hit a site that was firefox unfriendly (html incompatible) so I loaded IE just that once -- and BOOM -- my file search function doesnt work any more!! ... One case of a browser hostile site was checked and IE indeed rendered the site "correctly"; the site owner claimed their code was "universal". ...
    (sci.electronics.design)

Loading