473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

What is that ? -> $("container")

Hi there !

I was looking at ajaxpatterns.org when I read this piece of JS code :

var container;

window.onload = function()
{
if ($("container"))
{
var newContainer = document.create
document.getElementByTagName("body").removeChild($ ("container"));
document.getElementByTagName("body").insert
}

What is this $("container") ?? I never saw this syntax
I tried to find out on GG but nothing appeared.

Thx
Antoine

Nov 23 '05 #1
5 1676


an**********@gmail.com wrote:

if ($("container"))
{ document.getElementByTagName("body").removeChild($ ("container")); What is this $("container") ?? I never saw this syntax


Well someone being PHP or Perl "impaired" is probably writing that code
and has simply defined a function with the name $ taking a string
argument and then doing whatever that PHP or Perl "impaired" person is
missing in JavaScript.
So look for e.g.
function $ (argument) {
in their source code and check what the function body implements,
probably taking that string argument and looking for a variable or even
DOM node with the name/id.
$ is legal in identifiers in JavaScript but should be avoided.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 23 '05 #2
On 21/11/2005 15:19, an**********@gmail.com wrote:
I was looking at ajaxpatterns.org when I read this piece of JS code :
Providing a link would have helped, but I found where you probably saw it:

<http://www.ajaxify.com/run/dom/dom.js>

[snipped code]
What is this $("container") ??


A function call. A dollar symbol ($) is valid identifier start
character, along with letters and underscores (_). It's a bad choice
though, not least because dollars should be reserved for generated content.

You can see the definition at:

<http://www.ajaxify.com/run/Lib/js/util.js>

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Nov 23 '05 #3
an**********@gmail.com wrote:
What is this $("container") ?? I never saw this syntax
I tried to find out on GG but nothing appeared.


$ is just a function which they have defined.
Consider:

function $(name) {
alert(name);
}
$("test");

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Nov 23 '05 #4
Thx guys,

I saw this famous $() function and it does what you described : it just
returns back the elements passed through string arguments.
I don't know what to think about this. It seems "dirty" in a way, but
in another way it's really cool to get away from those millions
document.getElementById() ... :-)

Thx anyway

Antoine

Nov 23 '05 #5
an**********@gmail.com wrote:
What is this $("container") ?? I never saw this syntax
I tried to find out on GG but nothing appeared.

Thx
Antoine


It is a user defined function, probably from prototype.js if you were
looking at ajax stuff.

http://www.sergiopereira.com/articles/prototype.js.html
http://prototype.conio.net/

"Using the $() function
The $() function is a handy shortcut to the all-too-frequent
document.getElementById() function of the DOM. Like the DOM function,
this one returns the element that has the id passed as an argument.

Unlike the DOM function, though, this one goes further. You can pass
more than one id and $() will return an Array object with all the
requested elements. ... "

chuck
Nov 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dave Rahardja | last post by:
I've tried looking this topic up in the standard manual but came up empty... 1. What is the value of an unsigned integral type after it is decremented below zero? 2. What is the value of an...
2
by: CoolPint | last post by:
Can anyone clearly explain the difference between constant reference to pointers and reference to constant pointers? What is const int * & ? Is it a constant reference to a pointer to an...
12
by: Dario | last post by:
The following simple program behaves differently in Windows and Linux . #include <stdexcept> #include <iostream> #include <string> using namespace std; class LogicError : public logic_error {...
86
by: Michael Kalina | last post by:
Because when I asked for comments on my site-design (Remember? My site, your opinion!) some of you told me never to change anything on font-sizes! What do you guys think of that:...
6
by: Dan V. | last post by:
I am using: http://www.csscreator.com/version2/pagelayout.php and choose HTML 4.01 transitional as I think this means it will be supported by more browsers. However in Macromedia Dreamweaver...
2
by: news.hku.hk | last post by:
may i ask what is identifier ? because my teacher said my program have poorly selected identifiers.
6
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a...
7
by: Fendi Baba | last post by:
The function is called from opencalendar(targetfield). Thanks for any hints on what could be the problem. .............................................................. var...
2
by: Dan V. | last post by:
What do you recommend to use for saving time and get great results for making image and css buttons on a site? Also top tabs like for navigation. Separate question maybe is what is the best tool...
2
by: yogesh | last post by:
char TCGI::x2c(char *what) { register char digit; digit = (char) ((what >= 'A' ? ((what & 0xdf) - 'A')+10 : (what - '0'))); digit *= (char) 16; digit += (char) ((what >= 'A' ? ((what & 0xdf) -...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.