views:

477

answers:

3

Since the getElementById() function is new, I wanted another more reliable method to get a reference to an element based on its id.

Since I need to cut down on size, 10-20K for a framework is unacceptable. I just need the JS to fetch an element.

+12  A: 

getElementById isn't new. It's been around as long as getElementbyTagName, which was already asked about by you.

Jeff Yates
Haha, I just read that one too. @Jeremy - do some research first dude.
KyleFarris
Yeah, and how? Which site's gonna tell me which function appears in which standard?
Jenko
w3schools tells you (see link for getElementById in my answer).
Jeff Yates
@Kyle: Oh snap!
Jeff Yates
Look at the mojo on this question though Kyle, you got a measly 7 upvotes on your answer, Jeff got the whole enlightened badge for this.
altCognito
Yeah, that's rather disproportionate.
Jeff Yates
@Jeremy Rudd: 'Yeah, and how? Which site's gonna tell me which function appears in which standard?' ... https://developer.mozilla.org/en/Gecko_DOM_Reference leads to https://developer.mozilla.org/en/DOM/document.getElementById which contains a 'Specification' section.
Grant Wagner
A: 

There's a reliable method that works in all widely supported browsers that isn't new called getElementById()...

Garry Shutler
+3  A: 

My answer is the same as your previous question http://stackoverflow.com/questions/820369/alternative-to-getelementsbytagname/820399#820399 .

You can use the Sizzle CSS selector engine. Sizzle is the CSS selector engine that powers jQuery.

http://sizzlejs.com/

KyleFarris
"Dude, ok, once was enough. Too similar."
Jenko
Touché sir, touché.
KyleFarris
Haha! Just joking.
Jenko