Hi
I followed the discussions about 'how to make jquery more popular'
and I just want to point out that this is the kind of things that should
be learned to newcomers in a crash course.
$() is easy to understand as a steroid getElementById(), but to
understand that it returns a jQuery object belongs
more to the innards of jQuery. I'm using for time to time jQuery for 4
months and it is the kind things I'm avid to better understand.
get(0) or [1] ok got it, but will each() work ? is there a way to filter ?
Well I usually get the answer to such questions by myself, but I'd love
to see it discussed on some blogs around with pros and cons, before I
even really need it...
Ok, maybe I should write a few stuffs by myself before to tell others
what to do, but please take this as gentle suggestion, just "pointing
out"...
olivvv
Klaus Hartl wrote:
jazzle schrieb:
Why doesn't
$("#b6").selectedIndex = $("#s6").selectedIndex;
work? (Assuming #b6 and #s6 are similar select boxes of course. Copying
billing to shipping address BTW)
I know it's not really how jQuery code usually works, but would like to
understand why not.
What $("#b6") returns is a jQuery object that contains one or more
elements (nodes), e.g. the search result of the expression that you
passed in.
If you want to access DOM properties of an element you have get them out
ouf the jQuery object first. This can be done via the get(n) method or
with simple Array index notation:
var firstElem = $("div").get(0);
var secondElem = $("div")[1];
Be careful with that: It may be the case that there is no second
element, so if you try to access secondElem (which is undefined in that
case) it may throw an error:
secondElem.className = 'foo'; // may throw an error
In such cases it's better to stick to jQuery methods like each() to
prevent such errors.
Your example again (untestet):
$("#b6").get(0).selectedIndex = $("#s6").get(0).selectedIndex;
and more jQuerish (assuming that the value corresponds to the selected
index):
$('#b6').val( $("#s6").val() );
-- Klaus
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/