I want to iterate over an array of inputs that belong to certain class (eg."required"). How can I traverse it and get their values ? Something like
$$('input required').in开发者_C百科voke(function(e){
alert(?input value?)
});
thanks
You're close:
$$('input.required').each(function(i){
console.log($F(i));
});
All inputs with the class of required
will be iterated through and their value displayed to the Firefox console. If you don't use Firefox just change console.log
to alert
to see the results.
It works me.
example code:
document.observe("dom:loaded", function() {
var maxHeight = 0;
$$('.product-name').each(function(i){
var eleHeight = i.getHeight();
if (eleHeight > maxHeight){
maxHeight = eleHeight;
}
});
$$('.product-name').each(function(i){
i.setStyle({
height: maxHeight+'px'
});
});
});
精彩评论