How to remove the specific attribute from XmlDocument?

jQuery: How can I set the selected attribute to a next available option element if the currently selected option is disabled?

  • The console shows Blue, which is good and now I'd like to set theĀ  selected attribute to the next available (not disabled) option tagĀ  element and remove the selected attribute from the current disabled one. <select id="test"> <option >Red</option> <option selected disabled="Disabled">Blue</option> <option>Yellow</option> <option disabled="Disabled">Orange</option> <option>Green</option> </select> <script type="text/javascript"> console.log( $( "select#test option:selected" ).attr( "value" ) ); </script>

  • Answer:

    I think this will do: <script type="text/javascript"> var selected_option = $('#test option:selected'); if(selected_option.is(':disabled')) { selected_option.removeAttr('selected').nextAll(':not(:disabled)').first().prop('selected', true); } console.log($('#test option:selected').attr('value')); </script>

Caio Vaccaro at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.