[jQuery] Subscribe form / ajax / jQuery ?

[jQuery] Subscribe form / ajax / jQuery ?

Great!
So if I understand correctly, jquery can accept, as an argument to $(),
either an HTML element, $('P') to get all P tags, or a class/div reference,
$('#myDiv') or $('div.myClass').
A question for clarification's sake then.
1) Do single/double quotes matter?
2) You say that I can use $('DIV').val() to get/set the value of
    a DIV element. You also say I could use this too:
    $('DIV').get(0).value;
    I assume that if $() returned more than one element and I wanted to access
informatiom from the second one I could use
$('#YourEmailField').get(1).value;
    Is this a valid assumption?
3) You mentioned "this page to read more about class selectors" but didn't
include a page.    Care to share with the class for everyone's general
jollification? I assume you
    just forgot.
For the record, I greatly appreciate your input and the input of the other's
on this
list. You all really seem to know your stuff and I'm happy to be a part, no
matter how small, of this list.
<!----------------//------
andy matthews
web developer
certified advanced coldfusion programmer
ICGLink, Inc.
andy@icglink.com
615.370.1530 x737
--------------//--------->
-----Original Message-----
From: discuss-bounces@jquery.com [mailto:discuss-bounces@jquery.com]On
Behalf Of Michael Geary
Sent: Wednesday, June 28, 2006 1:10 PM
To: 'jQuery Discussion.'
Subject: Re: [jQuery] Subscribe form / ajax / jQuery ?
First problem: The argument to the $() function. Prototype takes an element
ID. jQuery takes a CSS or XPath expression, like the one you used in the
second line. Use $('#YourEmailField') if that is the element's ID.
Read this page to learn more about the CSS selectors you can use in $():
Second problem: The return value from $(). Prototype returns a DOM element.
jQuery returns a "jQuery object" (which I put in quotes because the object
doesn't really have a name, it's just the object that $() returns). This
object has a val() method which gets or sets the value property. Use
$('#YourEmailField').val() to get the value.
You can get to the actual DOM element with $('#whatever').get(0), so another
way to get your form value is:
var addy = $('#YourEmailField').get(0).value;
That does exactly the same thing as:
var addy = $('#YourEmailField').val();
But most jQuery users prefer the latter notation - get(0) is considered a
tool of last resort.
One last note: Your second line code is fine, but you can simplify it a tiny
bit if you want. Instead of using $('div#myDiv'), just use $('#myDiv').
Element IDs are unique, so there is no need to further qualify them with the
tag name.
OTOH, when you are using class selectors, you get better performance by
including the tag name, e.g. $('a.myLink') will find all of the A tags with
classname myLink faster than $('.myLink'). Class selectors use a brute force
search, so $('.myLink') has to search the entire DOM tree. $('a.myLink')
lets jQuery call getElementsByTagName to retrieve only the A elements, then
it searches only those elements for the classname.
-Mike
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

































































    • Topic Participants

    • andy