...

View Full Version : Different syntaxes



qwertyuiop
07-30-2006, 09:42 PM
Hi,
I've seen two different types of syntaxes when it comes to modifiying elements.

Syntax #1:
var element = document.createElement('div');
element.setAttribute('id', 'menu');

Syntax #2:
var element = document.createElement('div');
element.id = 'menu';

What's the difference? And what are they called?

felgall
07-30-2006, 10:28 PM
The first one is using the DOM2 setAttribute method while the second one is using the method that existed before the DOM standard was created (usually referred to as DOM0). Not all browsers support setting all attributes via the setAttribute method yet.

qwertyuiop
07-30-2006, 11:23 PM
So the second one is more widely supported? And are there any differences speed-wise? What are the pros and cons of each?

Thanks. :o

Kravvitz
07-31-2006, 04:33 AM
Using the first method you can run into several bugs, especially in IE.

I can't think of any cons to using the DOM0 method.

verginette
07-31-2006, 09:28 AM
hi everyone.. i am new here and i know you can help me with my problem.

i am thinking of a site where visitors could only enter my main page if they will click the support button which that support button would link to an ad.

can you suggest of a code?

thank you.

Kor
07-31-2006, 11:48 AM
verginette, please, don't cross-post. You have already:
http://www.codingforums.com/showthread.php?t=92372

Furthermore, this post here has nothing to do with this thread here.

jkd
07-31-2006, 03:20 PM
It's not just a DOM0-method - many of those were standardized as part of DOM2 HTML.

qwertyuiop
08-02-2006, 10:26 PM
How can I get DOM0 to work with attributes like tabindex?



element.tabindex = '1';

doesn't work.

Kravvitz
08-02-2006, 10:27 PM
JavaScript is case-sensitive.

The property is tabIndex, not tabindex.

http://www.w3.org/TR/DOM-Level-2-HTML/html.html



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum