In Javascript, one of the most common things you do is document.getElementById(‘someid’). But what if you got the Element from an Event and you want to use that Object with the Prototype Javascript Library or some other library that relies on using the ID?
In that case, you can’t just tack on the Prototype functions like: obj.addClassname(‘someclass’); You have to use an object that is extended with the Prototype or other library’s magic.
In Prototype, the easiest way to do that is to get the Object’s ID and use the $(‘someid’).someFunction(); methodology. Getting the ID is really simple, though I spent 20 minutes trying to find it on Google. Here’s how:
var ID = object.id;
There you go!
Byron
Ahhhhh…thank gawd that’s over! So simple but it took sooooo long to find the solution.
I hear you, man. Why do the little things eat up so danged much time???
how can i do this for the Internet Explorer….object.id for me only in Firefox,Opera,Netscape…but no IE
C4mp3r,
Uggg…I don’t know. I’ll need to try this at work. I don’t have IE here at home.
BB
Valuable information. Thanks to you I don’t have to trawl the web like you did for 20mins. Cheers!
i find statement like Object[“id of a html control”]. what it means.
Great info ! It’s working – remember to update your browser (crappy ie 6)