Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prototype cross browser syntax (asking again since nobody responded)

Status
Not open for further replies.

youngApprentice

Programmer
Jan 28, 2007
16
0
0
US
Hi All,

For the $ function in Prototype 1.5.1, which is the correct syntax to be cross browser:

$($('myContainer')).appendChild(myHeading);
or
$($('myContainer').appendChild(myHeading));

They both seem to work, and I need this to work in several browsers. The second one seems to be more inline with the "How Protoype extends the DOM" page.

TIA,

youngApprentice
 
Actually... why are you doing this in the first place? Surely the correct syntax is just:
Code:
$('myContainer').appendChild(myHeading);
The appendChild function returns the element that was appended... but you already have that as the variable myHeading, so the extra use of $ is redundant (imho).

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Thanks BabyJeffy,

Yes after re-reading Prototype's "How Prototype extends the DOM" three times, "Surely the correct syntax is just:" $('myContainer').appendChild(myHeading);

However when I read the note at the bottom of their explanation, it got me a little confused. So the syntax wouldn't be right for IE if you were to use one of their DOM extensions.

They state:
// this will error out in IE:
$('someElement').parentNode.hide()
// to make it cross-browser:
$($('someElement').parentNode).hide()

so at least for me, it's easy to see why I got confused.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top