next option jquery

trying to select next option drop down list by using a id identifier, but to no avail

here is the code

$('#chapter option:selected', 'select').removeAttr('selected').next('option').attr('selected', 'selected')

Answers


I assume #chapter is the <select> or one of its ancestors.

If that's the case, remove the context argument.

$('#chapter option:selected').removeAttr('selected')
              .next('option').attr('selected', 'selected');

The way you had it, you were effectively doing this:

$('select').find('#chapter option:selected').removeAttr(...

...which is looking for an element inside the <select> that has an option:selected descending from an elelent with the chapter ID.


EDIT: This answer was focused merely on why the selection wasn't working. It would be better to accomplish the ultimate task using the method in @Andy E's answer.

I'd recommend that one as the Accepted answer.


Need Your Help

Globalize3 multiple locale form

ruby-on-rails ruby-on-rails-3 internationalization globalize2

I have a problem regarding submitting multiple locale translations for model data within the same form. For example:

How to get sender widget with a signal/slot mechanism?

qt4

It's possible to bind more than one signal to one slot (isn't?). So, is there a way to understand which widget sends the signal? I'm looking for something like sender argument of events in .NET

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.