Re: [jQuery] what's the difference betweendocument.getElementById('id') and $('#id') ?
thanks Aaron, Michael! that makes it clear. On 1/16/07, Michael Geary [EMAIL PROTECTED] wrote: Now that it is laid out in front of me it's pretty obvious, but when you come into the thing cold, these things are not obvious. I think it would be a good idea to explicitly state what the object is, and that $ refers to it (I think that's right ... now I mention it I'm not quite sure if $ is an object reference or an operator ... ) - anyhow just a bit of clarification of the basics. It's neither of the above. :-) $ is not an operator. In JavaScript, the $ character can be used in names in the same way as a letter. $ is also not a jQuery object or a reference to one. at all. It is a *function* that returns a jQuery object. A good way to think of the $ function is that it's just like a constructor function (e.g. Date or Array), except you don't use the new operator with it, you just call it. Consider this code: // Give the $ function a more self-explanatory name var createQueryObject = $; // Create a query object for a specified query string var myQueryObject = createQueryObject('#test'); // Call a method of the query object myQueryObject.hide(); That is the same as: $('#test').hide(); Note also that $ and jQuery (used as a name in JavaScript code) are the same thing. So you could also write this code as: jQuery('#test').hide(); Or: var myQueryObject = jQuery('#test'); myQueryObject.hide(); -Mike ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/ -- Daniel McBrearty email : danielmcbrearty at gmail.com www.engoi.com : the multi - language vocab trainer BTW : 0873928131 ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] what's the difference betweendocument.getElementById('id') and $('#id') ?
yes. Thanks. I have it now. Any takers on my what is the jQuery object question? Is it simply an array of elements that have been selected? It may be kind of obvious, but it took me a few days to figure it. It might be good to explicitly say this somewhere early in the docs IMHO. thanks again. On 1/15/07, Dave Methvin [EMAIL PROTECTED] wrote: $(function () { self.focus(); $(#userresponse).setAttribute(autocomplete,off); $(#userresponse).focus(); }); I would do this: $(function () { self.focus(); $(#userresponse).attr(autocomplete,off)[0].focus(); }); There isn't a setAttribute method on a jQuery object, and I assume you want the DOM focus() method on #userresponse. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/ -- Daniel McBrearty email : danielmcbrearty at gmail.com www.engoi.com : the multi - language vocab trainer BTW : 0873928131 ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] what's the difference betweendocument.getElementById('id') and $('#id') ?
The jQuery object is a chunk of the DOM, on steroids. --Erik On 1/16/07, Daniel McBrearty [EMAIL PROTECTED] wrote: yes. Thanks. I have it now. Any takers on my what is the jQuery object question? Is it simply an array of elements that have been selected? It may be kind of obvious, but it took me a few days to figure it. It might be good to explicitly say this somewhere early in the docs IMHO. thanks again. On 1/15/07, Dave Methvin [EMAIL PROTECTED] wrote: $(function () { self.focus(); $(#userresponse).setAttribute(autocomplete,off); $(#userresponse).focus(); }); I would do this: $(function () { self.focus(); $(#userresponse).attr(autocomplete,off)[0].focus(); }); There isn't a setAttribute method on a jQuery object, and I assume you want the DOM focus() method on #userresponse. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/ -- Daniel McBrearty email : danielmcbrearty at gmail.com www.engoi.com : the multi - language vocab trainer BTW : 0873928131 ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/ ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] what's the difference betweendocument.getElementById('id') and $('#id') ?
On 16/01/07, Daniel McBrearty [EMAIL PROTECTED] wrote: yes. Thanks. I have it now. Any takers on my what is the jQuery object question? Is it simply an array of elements that have been selected? It may be kind of obvious, but it took me a few days to figure it. It might be good to explicitly say this somewhere early in the docs IMHO. thanks again. It is a collection of selected elements, that can be batch processed (events assigned, styles applied, classes added etc), but due the fact that multiple types of elements (div, span, input etc) can be selected, the methods of each element have to be accessed by index (using get(n).focus() or [n].focus()). It's really a pseudo array rather than a real array. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] what's the difference betweendocument.getElementById('id') and $('#id') ?
Now that it is laid out in front of me it's pretty obvious, but when you come into the thing cold, these things are not obvious. I think it would be a good idea to explicitly state what the object is, and that $ refers to it (I think that's right ... now I mention it I'm not quite sure if $ is an object reference or an operator ... ) - anyhow just a bit of clarification of the basics. It's neither of the above. :-) $ is not an operator. In JavaScript, the $ character can be used in names in the same way as a letter. $ is also not a jQuery object or a reference to one. at all. It is a *function* that returns a jQuery object. A good way to think of the $ function is that it's just like a constructor function (e.g. Date or Array), except you don't use the new operator with it, you just call it. Consider this code: // Give the $ function a more self-explanatory name var createQueryObject = $; // Create a query object for a specified query string var myQueryObject = createQueryObject('#test'); // Call a method of the query object myQueryObject.hide(); That is the same as: $('#test').hide(); Note also that $ and jQuery (used as a name in JavaScript code) are the same thing. So you could also write this code as: jQuery('#test').hide(); Or: var myQueryObject = jQuery('#test'); myQueryObject.hide(); -Mike ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] what's the difference betweendocument.getElementById('id') and $('#id') ?
$(function () { self.focus(); $(#userresponse).setAttribute(autocomplete,off); $(#userresponse).focus(); }); I would do this: $(function () { self.focus(); $(#userresponse).attr(autocomplete,off)[0].focus(); }); There isn't a setAttribute method on a jQuery object, and I assume you want the DOM focus() method on #userresponse. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/