html - Why does javascript not see the "selected" attribute on my select option? -


short version:

after inserting select element options dom ajax call "selected" attribute on option isn't recognized javascript. it's if it's not there though looking @ in firebug can see is.

long version:

i'm using jquery plugin generates "multi select" (select imitation checkboxes pretty much) based on actual html select options can have "selected" attribute. plugin checks if selected attribute exists doing

$(this).attr('selected') == true 

and if exists sets corresponding checkbox checked. works when load page normally. need reload data if user chooses filter , here problem is. new data fetched via ajax , plugin reapplied new markup "selected" attribute isn't considered present even though it's there before. other attributes work fine "selected" bizarrely enough doesn't. markup both when works , when doesn't.

<option value="1" selected="selected" warning="true"> text</option>

i'm scratching head on this. got suggestion?

forget jquery's confusingly named attr() method , attributes in general, , instead use selected property of option, boolean , works in major browsers released since 1996:

// assuming select list stored in variable called select alert( select.options[0].selected ); 

if must use jquery option, here's equivalent:

alert( $(this)[0].selected ); 

attributes never want, since incorrectly implemented in ie , ever represent initial value of aspect of element, not current value. jquery's attr() method uses properties internally.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -