I need to add img and input tags below an existing input. Below is my code:
function addElements(){
var inputTag1 = document.getElementById('break_sw');
var imgTag = document.createElement('img');
imgTag.setAttribute('style','border:0px;height:1px;width:30px;');
imgTag.setAttribute('scr','..//images/sample.gif);
breakSwInput.appendChild(imgTag);
var inputTag = document.createElement('input');
inputTag.setAttribute('id','new_input');
inputTag.setAttribute('name','new_input');
inputTag.setAttribute('id','new_input');
inputTag.setAttribute('type','button');
inputTag.setAttribute('onclick','buttonClick()');
inputTag.setAttribute('style','padding-right: 5px;');
breakSwInput.appendChild(inputTag);
}
Existing HTML Code (before insert). This is where I need to insert the new img and input elements after the "break_sw".
<tr id="row4">
<td>
<div>
<span>
<label>Dummy</label>
</span>
</div>
</td>
<td colspan="3">
<span>
<input name="create_sw" id="create_sw" type="button" onclick="buttonClick()>
<img style="border:0px;height:1px;width:30px;" scr="..//images/sample.gif">
<input name="break_sw" id="create_sw" type="button" onclick="buttonClick()>
</span>
</td>
</tr>
The result of the above code is incorrect. The newly added img and input were inside the input text.
<tr id="row4">
<td>
<div>
<span>
<label>Dummy</label>
</span>
</div>
</td>
<td colspan="3">
<span>
<input name="create_sw" id="create_sw" type="button" onclick="buttonClick()>
<img style="border:0px;height:1px;width:30px;" scr="..//images/sample.gif">
<input name="break_sw" id="create_sw" type="button" onclick="buttonClick()>
<img style="border:0px;height:1px;width:30px;" scr="..//images/sample.gif">
<input id="new_input" name="new_input" style="padding-right: 5px;" onclick="buttonClick()" type="button">
</input>
</span>
</td>
</tr>
MY DESIRED OUTPUT SHOULD BE:
<tr id="row4">
<td>
<div>
<span>
<label>Dummy</label>
</span>
</div>
</td>
<td colspan="3">
<span>
<input name="create_sw" id="create_sw" type="button" onclick="buttonClick()>
<img style="border:0px;height:1px;width:30px;" scr="..//images/sample.gif">
<input name="break_sw" id="create_sw" type="button" onclick="buttonClick()>
<img style="border:0px;height:1px;width:30px;" scr="..//images/sample.gif">
<input id="new_input" name="new_input" style="padding-right: 5px;" onclick="buttonClick()" type="button">
</span>
</td>
</tr>