View Full Version : Different syntaxes

07-30-2006, 09:42 PM
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?

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.

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

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.

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.

07-31-2006, 11:48 AM
verginette, please, don't cross-post. You have already:

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

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

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

element.tabindex = '1';

doesn't work.

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

The property is tabIndex, not tabindex.