I can't figure out how to sort through collections. The $$ selector (". First input") returns a set:

[<input type=​"checkbox" id=​"id-9" name=​"ids[]​" value=​"9">​, <input type=​"checkbox" id=​"id-23" name=​"ids[]​" value=​"23">​, <input type=​"checkbox" id=​"id-24" name=​"ids[]​" value=​"24">​, <input type=​"checkbox" id=​"id-27" name=​"ids[]​" value=​"27">​, <input type=​"checkbox" id=​"id-1" name=​"ids[]​" value=​"1">​] 

I check the marked elements, if checked, then put its id in the array:

 var checkedElemets = []; var elements = $$(".first input"); for(var i in elements){ if(elements[i].getValue('checked') != null){ checkedElemets.push(elements[i].getValue('checked')); } } 

The browser swears that there is no getValue method in the elements [i] object. Please help me understand my mistakes.

Moreover, the construction elements [i] .getValue ('checked') where i is the ordinal number of the element, in the console works fine:> elements [0]. GetValue ('checked') returns> "9"

  • Did you just try elements [i] .checked? - Rules
  • It is necessary to get the value of the element also added to the array - Mityaka
  • If elements [i] is a DOM node, then elements[i].Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ returns an attribute with the name Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ . For example: elements[i].value returns the value attribute. - Rules
  • And what did you use as a result? - Rules
  • elements [i]. attribute - Mityaka

1 answer 1

Thank you, figured out! Used

 elements[i].Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚