Replace an option at the given index with a new option. @param index the index of the option to remove @param newOption the new option to replace to indexed option
(final int index, final HtmlOption newOption)
| 214 | * @param newOption the new option to replace to indexed option |
| 215 | */ |
| 216 | public void replaceOption(final int index, final HtmlOption newOption) { |
| 217 | final ChildElementsIterator iterator = new ChildElementsIterator(this); |
| 218 | int i = 0; |
| 219 | while (iterator.hasNext()) { |
| 220 | final DomElement element = iterator.next(); |
| 221 | if (element instanceof HtmlOption) { |
| 222 | if (i == index) { |
| 223 | element.replace(newOption); |
| 224 | ensureSelectedIndex(); |
| 225 | return; |
| 226 | } |
| 227 | i++; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | if (newOption.isSelected()) { |
| 232 | setSelectedAttribute(newOption, true); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Add a new option at the end. |
no test coverage detected