سؤال

I use the following code to reset the selected index of a select list in IE:

$("#list")[0].selectedIndex = -1

However, that doesnt appear to work in FF and Chrome. Can anyone tell me what the correct way to achieve this would be?

هل كانت مفيدة؟

المحلول

Use the .prop method of jQuery. Documentation can be found here.

Get:

$("#list").prop("selectedIndex");

Set:

$("#list").prop("selectedIndex",-1);

نصائح أخرى

Why not this?

$("#list option").attr("selected", false);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top