These forums are currently read-only due to receiving more spam than actual discussion. Sorry.

It is currently Sat Dec 02, 2017 4:06 pm Advanced search

IDs, Classes and other objects in the DOM

Do you think the HTML spec should do something differently? You can discuss spec feedback here, but you should send it to the WHATWG mailing list or file a bug in the W3C bugzilla for it to be considered.

IDs, Classes and other objects in the DOM

Postby foniksonik » Wed Dec 12, 2007 4:32 pm

My proposal is for the browser to make the DOM more accessible through implicit calls to the ID array, class array and potentially other natural arrays such as attributes, etc.

Much of my javascripting is required by the lack of such access to these DOM objects. I think others will agree with me here. Why do I first need to create a variable then set it to an element(s) by class or id? Why can't I simply call that element directly? You might think this is a ECMA or Javascript feature but it's not... it is DOM scripting/manipulation/traversal and really should be a feature of the DOM itself or the implementation of it by the browser.

Each DOM object should pre-compile these arrays for me so I can grab elements/arrays of elements directly w/o having to resort to a javascript library to do the job for me.

Really this is just a browser/DOM implemented shortcut for getElementById and getElementByClassName, etc.

An example of this would be:

[code]<script language="javascript">
.myClass.onClick = function(){
this.style.display = (this.style.display == 'block') ? "none" : "block";
}

#myElementID.onSubmit = function(){
doSomething();
}


</script>[/code]

Additionally an implementation of XPATH would come in really handy here as well so that I can find child/parent/sibling elements easily again w/o needing a 3rd party library.

[code]
<script language="javascript">
(.toggleBlock >> a.toggleHandler).onClick = function(){
(this <> div.toggleBody).style.display = (this.style.display == 'block') ? "none" : "block";
}

// where >> means children and <> means sibling

</script>[/code]


The reasoning for this is twofold:

1) make code easier to write and read... no more vague variables holding already defined objects (don't define a class object array twice, once in the DOM and again in my custom variable)

2) speed up the whole thing and improve memory usage by moving these commonly used object arrays into the browser code (which is inherently more optimized and faster) as well as make these available as soon as the DOM is available (which currently requires a 3rd party library to ensure)
foniksonik
<h6>
 
Posts: 1
Joined: Wed Dec 12, 2007 3:58 pm
Location: Laguna Hills, CA

Postby zcorpan » Thu Dec 13, 2007 10:17 am

It seems like you're looking for the Selectors API, or maybe XBL2:

http://www.w3.org/TR/selectors-api/
http://www.w3.org/TR/xbl/

XPath is already available in most browsers:

http://www.w3.org/TR/DOM-Level-3-XPath/

The specific syntax you suggest wouldn't be possible to introduce without making incompatible changes to ECMAScript, as far as I can tell.
zcorpan
<article>
 
Posts: 807
Joined: Tue Feb 06, 2007 8:29 pm
Location: Sweden


Return to Feedback on the Specs

Who is online

Users browsing this forum: No registered users and 1 guest