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/

Reply via email to