开发者

How to register HTML text with DOM?

开发者 https://www.devze.com 2023-04-12 18:37 出处:网络
I get 开发者_如何学运维following text from the as a result of a AJAX request. <div class=\"selectMe\" >

I get 开发者_如何学运维following text from the as a result of a AJAX request.

<div class="selectMe" >
    <select name="clientAcc" id="clientAcc" style="width: 144px;" >
         <option>JOHN</option>
         <option selected="selected">BOB</option>
    </select>
</div>

what i want to do is register this node in HTML DOM and access the select component as document.getElementById("clientAcc"). I dont know how to do this? can some one please help me. thanks in advance


Example

var data = <div class="selectMe"> //... plug your ajax response here,
    myDiv  = document.createElement('div');
myDiv.id = 'divClientAcc';
myDiv.innerHTML = data;
document.body.appendChild(myDiv);

Do note that you cannot have two elements with the same id (clientAcc). You'll have to change/drop the id of the inner select or the appended div.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号