views:

114

answers:

3

AFAIK, the JQuery ID selector:

var ctlId = $('#' + strControlId);

gets translated into a call by document.getElementById.

Questions:

  • Is document.getElementById supported by ALL the browsers?
  • I am currently using the find object function found below for selecting an ID. Would JQuery selector essentially do the same thing?
+5  A: 

No,

var ctlId = $('#' + strControlId);

results in a jquery object of which, the position, $('#' + strControlId)[0] is the result of document.getElementById

I would recommend moving rapidly and forcefully away from Macromedia javascript as soon as you possibly can. Nasty stuff and you'll learn a lot of currrently very poor practice for javascript if you keep using it (unfortunately).

EDIT: In response to a comment below regarding the history of MM javascript. I was going to reply as a comment, but I figured I'd likely waffle so I may as well respond properly here.

The history of MM javascript probably isn't all that interesting in this day and age, mostly because all MM javascript has is history - by which I mean it's stuck in a timewarp of 6+ years ago and is showing no signs of catching up (or even acknowledging) the incredible changes that have happened in the javascript community.

(I mean, for crying out loud, I can know actually use the phrase 'javascript community' and people will nod their head sagely rather than wetting themselves with laughter).

MM javascript is the code we used to have to write when the DOM was your enemy and every mention of javascript coding was met with screams of terror. MM tried to make it easier for designers to concentrate on design and markup and not have to worry about the irritating bits like button rollovers and menu drop downs. We've moved on, javascript has moved on, Macromedia javascript functionality has stayed the same.

Steerpike
+1 for whaling on MM's atrocious scripts :-)
NickFitz
+3  A: 
  1. Not by all browsers, but by all modern ones. Netscape 4 didn't support it. Some browsers don't support Javascript at all...
  2. Macromedia write horrible Javascript. It looks like they're searching across frames, which jQuery won't do, and you probably don't want to do. Stick with jQuery - it's much nicer...

Edit: IE, FireFox, Safari Opera have all supported it for years... Chrome has supported it since it was created.

d.layers is for Netscape 4 - AFAIK it didn't exist before or after.

Greg
And again: +1 for whaling on MM's atrocious scripts :-)
NickFitz
Searching across frames is a bad thing. You can have the same ID used in both frames - which one are you going to get back?
Greg
No idea about .NET - I do PHP mostly
Greg
A: 

All major browsers support getElementById (IE, Firefox, Safari, Chrome, Opera, etc.)

MM function will return a standard DOM node with no special new functions attached to it.

jQuery on the other hand will return a jQuery object which is a kind of array with many more functions attached to it (visual effects functions and more).

jQuery function also works with css selectors syntax to search for the right nodes, which I don't think the MM function does.

Hope this helps

MaxiWheat
I can get the DOM node using : $('#' + strControlId).get(0); Can I use this to replace the MM function?
Yes you can do this, this will actually lead to the same result. However I don't know how the performance compares from one to the other.
MaxiWheat