Ahmad Farid
Ahmad Farid

Reputation: 14774

How to remove selection from a listbox in html by javascript and jQuery?

After I click an item on a listbox, I'll do this processing then I need to remove this selection as it was at the first time so that I can click the same item again and fire the event of selected index change.

Upvotes: 2

Views: 8104

Answers (1)

Andy E
Andy E

Reputation: 344575

Set the selectedIndex property to -1:

// Plain JS:
document.getElementById("myList").selectedIndex = -1;

// Using jQuery to select the element:
$("#myList")[0].selectedIndex = -1;

Working demo: http://jsfiddle.net/n84AW/

Upvotes: 8

Related Questions