L
L
linux20002011-01-25 15:04:28
Google Chrome
linux2000, 2011-01-25 15:04:28

Chrome and reset select via jQuery

There is a line written in jQuery:

$('#styleGallery option:selected').removeAttr('selected');

Which should reset the selection in the select element.
In FF, everything works with a bang, and after the line is executed, the first element in the list becomes active.
In Chrome, select is reset. And the “empty line” becomes active, which chrome itself adds to the select element.

What is the right way to make it possible to “reset” the selection of the select element in both rows?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Antelle, 2011-01-25
@Antelle

I would do this:
$("#select").val($("#select option:first").val());

R
rakot, 2011-01-25
@rakot

Not sure , but try:
$('#styleGallery option:first').attr('selected','selected');

A
Alexander Keith, 2011-01-25
@tenbits

Or like this:

$('select option:first').attr('selected','1');

S
Sererator, 2011-01-25
@Serator

Add the selected attribute to the first option element.

A
APismennyj, 2012-07-27
@APismennyj

For a select with a data-filter class, it would look like this:
$('select.data-filter').prop('selectedIndex',0);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question