473,748 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What do these dollar signs and parenthesis do?

What is going on here with the dollar signs and parenthesis?

$(document).rea dy(function(){
$("li").behavio r("click",funct ion(){
$(this).load(me nu.html");
});
});

And when do you use click vs. onclick? Is onclick only an attribute
thing?

Thanks.

Jun 27 '08 #1
14 9853
On Apr 20, 12:54 pm, "gimme_this_gim me_t...@yahoo.c om"
<gimme_this_gim me_t...@yahoo.c omwrote:
What is going on here with the dollar signs and parenthesis?

$(document).rea dy(function(){
$("li").behavio r("click",funct ion(){
$(this).load(me nu.html");

});
});

You might get a better answer if you can give a complete example on a
page that works. One should note that the dollar sign $ is used to
indicate a variable in the server side script php, and unlike in JS
labeling of variables is required every time they are used. In JS you
might see "var something" once, and often the script will work even if
you forget to declare the variable. However in php you will see
"$something " and this must be used every time "something" is needed.
Just a short bit of php code often looks a lot like a short bit of JS
code. The two scripts are just enough alike to get you in trouble if
you just seldom write one of them. You have to keep thinking that you
are writing php and not JS, for example.
Jun 27 '08 #2
Thanks cwdjrxyz,

I haven't written any PHP - so I didn't recognize it.

The example comes from a slide I perused in a YUI presentation.

On Apr 20, 11:15*am, cwdjrxyz <spamtr...@cwdj r.infowrote:
On Apr 20, 12:54 pm, "gimme_this_gim me_t...@yahoo.c om"

<gimme_this_gim me_t...@yahoo.c omwrote:
What is going on here with the dollar signs and parenthesis?
$(document).rea dy(function(){
$("li").behavio r("click",funct ion(){
$(this).load(me nu.html");
});
});

You might get a better answer if you can give a complete example on a
page that works. One should note that the dollar sign $ is used to
indicate a variable in the server side script php, and unlike in JS
labeling of variables is required every time they are used. In JS you
might see "var something" once, and often the script will work even if
you forget to declare the variable. However in php you will see
"$something " and this must be used every time "something" is needed.
Just a short bit of php code often looks a lot like a short bit of JS
code. The two scripts are just enough alike to get you in trouble if
you just seldom write one of them. You have to keep thinking that you
are writing php and not JS, for example.
Jun 27 '08 #3
gi************* ******@yahoo.co m wrote:
What is going on here with the dollar signs and parenthesis?

$(document).rea dy(function(){
$("li").behavio r("click",funct ion(){
$(this).load(me nu.html");
});
});
They make for very obscure javascript source code (and disregard a
specified language convention). The - $ - signs are Identifiers, and the
parenthesise that follow them are the wrappers of arguments lists to
function calls (to all practical purposes they are 'call operators').
Meaning that the Identifier - $ - must have been assigned a reference to
a function object (though you will have to look at the rest of the code
involved to find out which function object, as it could be any).
And when do you use click vs. onclick?
That question has on meaning. The - click - above is just a string
literal, any meaning it may have is determined by whichever -
behaviour - method has been defined for whichever object is returned
from whichever functions has been assigned to whichever variable has
the - $ - Identifier. It all depends on the context, and the rest of the
code in that context.
Is onclick only an
attribute thing?
No.

Richard.

Jun 27 '08 #4
Thanks very much Richard.
Jun 27 '08 #5
cwdjrxyz wrote:
On Apr 20, 12:54 pm, "gimme_this_gim me_t...@yahoo.c om"
<gimme_this_gim me_t...@yahoo.c omwrote:
>What is going on here with the dollar signs and parenthesis?

$(document).re ady(function(){
$("li").behavi or("click",func tion(){
$(this).load(m enu.html");

});
});


You might get a better answer if you can give a complete example on a
page that works. One should note that the dollar sign $ is used to
indicate a variable in the server side script php, and unlike in JS
labeling of variables is required every time they are used. In JS you
might see "var something" once, and often the script will work even if
you forget to declare the variable. However in php you will see
"$something " and this must be used every time "something" is needed.
Just a short bit of php code often looks a lot like a short bit of JS
code. The two scripts are just enough alike to get you in trouble if
you just seldom write one of them. You have to keep thinking that you
are writing php and not JS, for example.
That is Prototype syntax, http://www.prototypejs.org/.

$('id') is a prototype shorthand for document.getEle mentById('id') and
so on.

BR, Tumi
Jun 27 '08 #6
On Apr 21, 3:12 pm, Tuomo Tanskanen <tumi_NOSP...@t anskanen.org>
wrote:
cwdjrxyz wrote:
On Apr 20, 12:54 pm, "gimme_this_gim me_t...@yahoo.c om"
<gimme_this_gim me_t...@yahoo.c omwrote:
What is going on here with the dollar signs and parenthesis?
$(document).rea dy(function(){
$("li").behavio r("click",funct ion(){
$(this).load(me nu.html");
});
});
You might get a better answer if you can give a complete example on a
page that works. One should note that the dollar sign $ is used to
indicate a variable in the server side script php, and unlike in JS
labeling of variables is required every time they are used. In JS you
might see "var something" once, and often the script will work even if
you forget to declare the variable. However in php you will see
"$something " and this must be used every time "something" is needed.
Just a short bit of php code often looks a lot like a short bit of JS
code. The two scripts are just enough alike to get you in trouble if
you just seldom write one of them. You have to keep thinking that you
are writing php and not JS, for example.

That is Prototype syntax,http://www.prototypejs.org/.
It may be similar to that used in Prototype.js, but I doubt it's from
that library - Prototype.js does not define "ready", "behavior" or
"load" functions.

There is another library sometimes mentioned in this group that seems
a more likely candidate.
--
Rob
Jun 27 '08 #7
On Apr 20, 12:54*pm, "gimme_this_gim me_t...@yahoo.c om"
<gimme_this_gim me_t...@yahoo.c omwrote:
What is going on here with the dollar signs and parenthesis?
$(document).rea dy(function(){
$("li").behavio r("click",funct ion(){
$(this).load(me nu.html");
});
});
For some reason no one wants to give you the straight answer.
This is jQuery syntax. http://www.jquery.com

Matt Kruse
Jun 27 '08 #8
On Apr 21, 5:47*pm, Matt Kruse wrote:
On Apr 20, 12:54*pm, "gimme_this_gim me_t...@yahoo.c om"

<gimme_this_gi mme_t...@yahoo. comwrote:
>What is going on here with the dollar signs and parenthesis?
$(document).re ady(function(){
$("li").behavi or("click",func tion(){
$(this).load(m enu.html");
});
});

For some reason no one wants to give you the straight answer.
This is jQuery syntax.http://www.jquery.com
It is not JQuery syntax. There is no such thing as JQuery syntax (nor
Prototype syntax), the code is javascript and so must use javascript
syntax. The code may be calling JQuery functions and methods, but then
it may also be calling the functions and methods of code that is (by
coincidence or imitation) indistinguishab le from JQuery in the
external appearance of the functions/methods used above.
Jun 27 '08 #9
On Apr 21, 12:02*pm, Henry <rcornf...@rain drop.co.ukwrote :
It is not JQuery syntax. There is no such thing as JQuery syntax (nor
Prototype syntax), the code is javascript and so must use javascript
syntax. The code may be calling JQuery functions and methods, but then
it may also be calling the functions and methods of code that is (by
coincidence or imitation) indistinguishab le from JQuery in the
external appearance of the functions/methods used above.
You can be intentionally obtuse and argumentative all you want, but
that doesn't actually help anyone.

The example syntax most closely resembles jQuery, from my experience.
And since the code snippet comes directly from a presentation by John
Resig, author of jQuery, the original poster would probably be most
interested in checking out jquery.com.

Similarly, if anyone was asking about code like
var panel_one = new YAHOO.widget.Pa nel("panel_one" , {} );
it would be logical to point them to YUI, although the code isn't
necessarily from YUI.

And just for fun, I'll give more info on the code:
>$(document).re ady(
This command takes a function as an argument, to be executed when the
DOM is ready to be manipulated, but before window.onload is fired.
function(){
This is the beginning of an anonymous function which is the argument
to ready()
$("li").behavio r("click",
The $() function, in jQuery and many other libraries, is a selector.
It's argument is typically a CSS selector used to identify elements in
a page which will then be somehow manipulated. In this case, $("li")
will select all "li" elements in the page.
The .behavior syntax isn't something I recognize, but maybe was
included as an example of behavior-driven syntax. In jQuery, you would
typically just write .click(function ) which would specify a function
to fire when the "onclick" event is fired.
So this line is attaching a function to be execute onclick of all LI
elements in the page.
function(){
$(this).load("m enu.html");
}
This is the function that will be fired when an LI is clicked.
In this example, 'this' will be a reference to the element itself, and
passing it to the $() function just selects it and makes the jQuery
functions available.
In this case, .load() is called which is an AJAX shortcut to load the
specified file and replace the inner content of the selected element
with the content returned from the AJAX call.
);
}
);
And those are there to close everything off.

Sometimes the over-abundance of $(){} and anonymous functions can make
this style of development a bit cryptic. It helps to format the
source. I also add some layers on top of this syntax to avoid so many
anonymous functions, etc. This certainly is only one way to develop
javascript, and other libraries and reusable code use entirely
different approaches. Pick the one that makes sense to you, or none at
all :)
Matt Kruse
Jun 27 '08 #10

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

Similar topics

50
4312
by: Jerry Sievers | last post by:
<venting> Fellow coders; I just get off the phone today with some clueless headhunter and after listing for her (very proudly I might add) my OS and dev tools platforms of choice; Linux/Apache/Postgres/PHP I get a few moments of silence and she mentiones to me some new wizzy
54
6569
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO FRICKIN' COOL!!! ***MAN*** that would save me a buttload of work and make my life sooooo much easier!" As opposed to minor differences of this feature here, that feature there. Variations on style are of no interest to me. I'm coming at this from a...
29
22189
by: Mark Hahn | last post by:
We are considering switching to the dollar sign ($) for self, instead of the period ( . ) we are using now in Prothon. Ruby uses the at-sign (@) for self, but our new usage of self also includes replacing the period for some attribute references, as in obj$func() versus obj.func(), and too many programs treat that as an email address and screw it up. Also the S in the symbol $ reminds one of the S in $elf. Can people from outside the...
2
3676
by: Martin Høst Normark | last post by:
Hi everyone Has anyone got the least experience in integrating the Digital Signature with an ASP.NET Web Application? Here in Denmark, as I supose in many other countries, they're promoting the digital signature. A lot of people already has one, to do their taxes, and much more. I have to use for a business-to-business e-commerce solution, where it's vital that the right user is being logged on, and not give his username and password...
4
1422
by: mantrid | last post by:
Hello Hope you can help. I have been using the code below to move elenents around the page. This has worked fine until I put some arguments into the functions so I could use them in many places with out having to create lots of slightly different functions. The code that has now stoped working is below. My javascript is not great and I have been struggling with this all day. Can anyone see where Ive gone wrong Thanks Ian
6
2249
by: shaqattack1992-newsgroups | last post by:
Hello Everyone, I'm using the following on a form in my database: =(-Int(-Sum((IIf(=Yes,((*)+()), (((*)+)*1.06))*100))))/100 In this case, I want to calculate a total for an order. If the LineTaxExempt field is checked (meaning tax exempt), the total is
2
3043
by: Yorian | last post by:
I just started to try regexps in php and I didn't have too many problems, however I found a few when trying to build a templte engine. The first one is found is the dollar sign. In my template I would like to write this: {$var} where var ofcourse will be replaced by the real var however I'm having trouble with the dollar sign I do escape the it though, my regexp:
2
2320
by: johnson4 | last post by:
Im wanting to display a dollar sign on my wap application, which requires that the cell phone is served with $$ to display $. Therefor I'm trying to find an easy way, in my php code, that will always add a dollar sign next to any existing dollar sign. so that dollar signs are always served in pairs The content is residing in a MySQL database. Thanks for any help that can be offered.
4
1460
by: mattG | last post by:
I have a scenario where I have these things that take up (x) number of space. I know the max number of space I will ever have is 512. I am trying to figure out a way to write a formula or whatever will make it work to tell me how many of these things I can put in this space. So example I want to put 60 of these thing that take up (21) units each. Well given that I cannot go over 512 the max I am able to put in any one space is 29. ...
0
8983
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8822
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9359
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9236
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6792
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3298
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.