Nick
Nick

Reputation: 7525

JQuery selecting by ID

AFAIK, the JQuery ID selector:

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

gets translated into a call by document.getElementById.

Questions:

Upvotes: 1

Views: 258

Answers (3)

Steerpike
Steerpike

Reputation: 17544

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.

Upvotes: 6

Greg
Greg

Reputation: 321578

  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.

Upvotes: 3

MaxiWheat
MaxiWheat

Reputation: 6251

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

Upvotes: 0

Related Questions