mplungjan
mplungjan

Reputation: 178215

Siblings give Object #<HTMLSelectElement> has no method 'each'

What am I missing here?

As part of an answer to How can i change options in dropdowns if it is generated dynamically?

I have an issue inside an onchange. I want to set all the siblings values to the value of the changed select

$("select").on("change",function() {
  var idx=$(this).val();
  console.log($(this).attr("id"),$(this).val())
  $(this).siblings("select").each(function() {
     $(this).val(idx);
  });
});

Here is the generated code in a JSFIDDLE

I have seen

How do i get the value of all other dropdowns when one of them is changed

but I prefer to find the reason for my error

Upvotes: 1

Views: 2043

Answers (1)

Ram
Ram

Reputation: 144699

You are using the val method as a property.

var idx=$(this).val;
//            ----^

http://jsfiddle.net/Vr5Je/

You can also use the val method instead of each:

$("select").on("change", function() {
    $(this).siblings("select").val(this.value);
});

http://jsfiddle.net/Pq2vq/

Upvotes: 2

Related Questions