javascript - setting attribute on select not persisting -


i have select input i'm setting multiple attribute via jquery. have console.log confirming code functions correctly, if console.log again no longer there. suggestions?

thisquestionhtml block of html code (2 divs wrapped around select statement i'm casting jquery object.

line 1: $(thisquestionhtml).find('.answervalue').attr('multiple','multiple'); line 2: console.log($(thisquestionhtml).find('.answervalue').attr('multiple','multiple')); line 3: console.log($(thisquestionhtml)); 

line 1 : non-debug code i'm expecting set it

line 2: debug code confirming being set. returns select statement complete multiple="multiple"

<select class=​"answervalue" data-questionid=​"a0nj0000008zwjomas" multiple=​"multiple">​</select>​ 

line 3: debug code returns select statement without multiple attribute.

<div class=​"control-group">​     <span class=​"control-label">​ms picklist question​</span>​     <div class=​"controls">​         <select class=​"answervalue" data-questionid=​"a0nj0000008zwjomas">​</select>​     </div>​ </div>​ 

you're creating new jquery object on each of 3 lines because thisquestionhtml html string. jquery isn't updating string, thisquestionhtml never changed.

line 2: debug code confirming being set.

this^ not true, setting value once again (note 2 arguments attr()).

store reference object instead of creating new each time:

var obj = $(thisquestionhtml); obj.find('.answervalue').attr('multiple','multiple'); console.log(obj); // contains updated select 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -