I ended up in a strange case where, as far as I know, two things that should act the same way behave in a completely different way.
If I have two selection menus per page, one static menu is hardcoded in HTML and one is added to the body at runtime using jQuery. Then I turn off the first option in both selection menus. When both menus are displayed, their first parameters are disabled as expected, however a dynamically added menu automatically sets the value for the second parameter, while the static menu still has the first one selected.
http://jsfiddle.net/hm3xgkLg/1/
HTML:
<select class="dropMenu"> <option value="1">First</option> <option value="2">Second</option> <option value="3">Third</option> <option value="4">fourth</option> </select>
JavaScript:
var arr = [ {val : 1, text: 'One'}, {val : 2, text: 'Two'}, {val : 3, text: 'Three'}, {val : 4, text: 'Four'} ]; var sel = $('<select class="dropMenu">').appendTo('body'); $(arr).each(function() { sel.append($("<option>").attr('value',this.val).text(this.text)); }); $('.dropMenu option:nth-child(1)').attr('disabled', 'disabled');
Why do these two seemingly identical selection menus behave differently? I would like both actions, like a static menu (to keep the 1st value selected), perhaps?
It should also be noted that I tried to wrap the disable function in $ (document) .ready to eliminate the problem with showing the menu, but there were no changes. I also tried to have two different classes with two separate calls to disable the parameters, to make sure that it did not come across somehow without any changes.