Hi Mike, Thanks for the explanation. That clears up a lot of questions I had, especially the part about the $ and it's relationship to the DOM elements. I guess I assumed I was getting a DOM element back because I have been using Prototype for so long, that it's kinda of what I expected to get out of using the $.
Again, many thanks, Shao On Aug 22, 2:33 pm, "Michael Geary" <[EMAIL PROTECTED]> wrote: > So the original code you posted was different from the actual code, eh? No > wonder I couldn't see what the problem was! ;-) > > This is why people always recommend posting a link to a test page, not a > code snippet. And especially not a modified code snippet that is "similar" > to the actual code but leaves out the key part that is actually going wrong. > > Not complaining, just suggesting for next time. > > So let's address the thing you're wondering about now. > > In jQuery, when you call $(whatever), you do *not* get back a DOM element. > You get a jQuery object, which is an *array* of DOM elements. (It's not an > actual JavaScript Array, but it has array-like .length and [0]..[n] > properties.) > > So, if you want to call jQuery methods, you call them on the jQuery object > directly. If you want to access DOM methods and properties directly, you > first need to get a reference to one of the DOM elements in the jQuery > object array. > > You can do that either by calling .each() on the jQuery object, or by > referencing the DOM elements directly with array notation. In the case where > you know there's only a single DOM element in the array (because you used an > #id selector), you can use [0] to get to the DOM element. > > One tip: I recommend using a $ prefix on variables that hold jQuery objects. > The $ is reminiscent of the $() call, and it helps keep track of which > variables are jQuery objects and which ones are DOM elements (or other > data). > > For example: > > var $test = $('#test'), test = $test[0]; > $test.slideDown('slow'); // call a jQuery method > alert( test.id ); // access a DOM property > > And in your sample I'd suggest a $src property instead of src: > > onclick="someFunction({ $src:$('someID'), otherParams:.... }); > > function someFunction( a ) { > a.$src.slideDown('slow'); // call a jQuery method > alert( a.$src[0].id ); // access a DOM property > } > > It can be hard to remember whether a variable is a jQuery object or a DOM > object, and this $ prefix convention really helps keep that straight. > > -Mike > > > From: Shao Kang Tat > > > Actually one thing is solved, it's because when I was using > > Prototype, the call was > > > onclick="someFunction({src:$('someID'), otherParams:....}); > > > for jQuery it had to be modified to be passed in as $('#someID'), > > > so now the function on the receiving end works with > > obj.attr("class") etc...however doing direct manipulation > > like obj.className or obj.id still returns undefined... > > Not sure why but as long as I can still get to the attributes > > then we're good. > > > Thanks! > > > Shao