javascript - jQuery get area to modify by ID then by ID of componet -


hey can not seem work in jquery though know can:

my html code:

<div class="cd-panel from-right" id="va">     <header class="cd-panel-header" style="max-width: 600px;">         <h1 style="margin-top: 5px;" id="panheading"></h1>     </header>     <div class="cd-panel-container" style="max-width: 600px; width: 600px;">     [more html code here...]     <div class="input-group">        <div class="input-group-addon">           <span class="glyphicon glyphicon-envelope"></span>        </div>        <div class="col-sm-10">           <input name="requestid" disabled="true" class="form-control input-sm"             id="requestid" style="width: 520px; max-width: 520px;" type="text">        </div>     </div>     [more html code here...] </div> <div class="cd-panel from-right" id="vda">     <header class="cd-panel-header" style="max-width: 600px;">         <h1 style="margin-top: 5px;" id="panheading"></h1>     </header>     <div class="cd-panel-container" style="max-width: 600px; width: 600px;">     [more html code here...]     <div class="input-group">        <div class="input-group-addon">           <span class="glyphicon glyphicon-envelope"></span>        </div>        <div class="col-sm-10">           <input name="requestid" disabled="true" class="form-control input-sm"             id="requestid" style="width: 520px; max-width: 520px;" type="text">        </div>     </div>     [more html code here...] </div> 

and jquery code:

if (responce["persondata1"][0].requestid != 1) {    $('#va > #requestid').val(responce["persondata1"][0].requestid); } 

but never puts value inside requestid text box va though does have value requestid. if this:

$('#requestid').val(responce["persondata1"][0].requestid); 

then has value inside text box.

what missing?

you need use, rid of > looks immediate child , requestid not child of va element.

$('#va #requestid').val(responce["persondata1"][0].requestid) 

also note identifiers in html must unique. can assign class , use like

 <input name="requestid" disabled="true" class="form-control input-sm requestid"  style="width: 520px; max-width: 520px;" type="text"> 

and then

$('#va .requestid').val(responce["persondata1"][0].requestid) 

Comments