[Javascript] Something better than getElementById
Terry Riegel
riegel at clearimageonline.com
Mon Oct 24 10:14:14 CDT 2005
Paul,
Thanks for your answer. It is very helpful.
I am starting to recraft my pages and need a good tutorial on parsing
stings with javascript for someone with a heavy background in BASIC
style programming and very little understanding of Regular
Expressions. Any ideas?
Here is a BASIC style instruction I need to convert to Javascript
a="nor pri"
b="sel"+right(a,length(a)-3)
RESULT:
a="nor pri"
b="sel pri"
Thanks for any help.
Terry
On Oct 22, 2005, at 2:53 AM, Paul Novitski wrote:
> At 05:08 PM 10/21/2005, Terry Riegel wrote:
>
>> The only reason I need to getElementById is to set the background
>> color to indicate the link is selected. Is there a way to set an
>> attribute without looking up the id? I am looking for ways to speed
>> up my pages, some have hundred's of ID's.
>>
>
> Terry,
>
> You can pass references to the objects themselves instead of their
> ids:
>
> <tag onclick="doSomething(this);">
> ...
> function doSomething(argObject)
> {
> argObject.className = "selected";
> }
>
> If you prefer to avoid inline scripting, as I do, you can
> accomplish the same thing this way:
>
> function Initialize()
> {
> ...
> oObject.onclick = doSomething;
> }
>
> function doSomething(evt)
> {
> // cancel event-bubbling
> if (evt) { event = evt; }
> event.cancelBubble = true;
>
> // change class
> this.className = "selected";
> }
>
> Peter-Paul Koch has some good tutorials on event processing in
> javascript at http://www.quirksmode.org/
>
> Regards,
> Paul
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
More information about the Javascript
mailing list