Thanks for the explaination. The reason for my request was my curiosity of
what exactly makes up the JQuery Object. For example, I didn't understand
that [0] is a reference to the first DOM object.
I ran this to try to look at the Object (using 1.04):
-------------------------------------------
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<form>
<input id="test" class="test" type="text" name"test">
<input id="test2" class="test" type="text" name"test">
</form>
<script type="text/javascript">
<!--
$(document).ready(function(){
var t = $(".test");
var s;
for (property in t)
{
s = s + "<br><br><hr /><br><br> "+property.toString()+" :
"+t[property].toString();
}
document.write(s.toString());
});
//-->
</script>
</body>
</html>
---------------------------------------
and learned quite a bit. (Although the page never fully loads, not sure
why). Anyway, I would recommend looking at this page for anyone who wants to
learn more.
(If there is a better way to look at the Object, please post here)
- Rich
malsup wrote:
>
>> I second the request for a good understanding of what the JQuery object
>> is.
>
>
> The jQuery object is just a JavaScript object (like Date or Array).
> It encapsulates zero or more DOM elements and lets you manipulate
> those elements using the jQuery API.
>
> var jq = $('.myClass');
>
> The statement above selects all elements that have a class of
> 'myClass' and wraps them in an object - the jQuery object. Once those
> elements are wrapped in a jQuery object you can use the jQuery API to
> do all kinds of things with them. Like show them all:
>
> jq.show();
>
> or add a click event handler to all of them:
>
> jq.click(function() { alert ('I was clicked'); });
>
> or access each of the selected DOM elements:
>
> jq.each(function(i) {
> // 'this' is the DOM element inside the 'each' method
> this.innerHTML = 'my index is ' + i;
> });
>
> That's really the nuts and bolts of it. jQuery lets you easily select
> elements in the DOM and do something with them. It's selection
> capabilities are very powerful and very fast. And it's API is quite
> extensive.
>
> You'll also find that most of the functions in the jQuery API return
> the jQuery object on which they operate. This means they are
> chainable and this is great when you want to do more than one thing
> with the selected elements. The examples above could be combined into
> a single statement like this:
>
> $('.myClass').show().click(function() {
> alert ('I was clicked');
> }).each(function(i) {
> this.innerHTML = 'my index is ' + i;
> });
>
> Mike
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
>
--
View this message in context:
http://www.nabble.com/what%27s-the-difference-between-document.getElementById%28%27id%27%29-and-%24%28%27-id%27%29---tf3017662.html#a8391034
Sent from the JQuery mailing list archive at Nabble.com.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/