Reputation: 2673
<br>
should be added dynamically. I've used the following script.
HTML code
<input ...../>
<input ...../> <br>
<input ...../>
<input ...../> <br>
JS
var mybr = document.createElement('br');
var inputs = document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
if (i % 2 == 0) {
// inputs[i].outerText=inputs[i].outerText+"<br><br>";
inputs[i].appendChild(mybr);
}
}
But it doesn't work. Any idea?
Upvotes: 2
Views: 816
Reputation: 2565
youn can replace :
inputs[i].appendChild(mybr);
by:
inputs[i].outerHTML+='<br/>' ;
<input ...../>
<input ...../> <br>
<input ...../>
<input ...../> <br>
<script type="text/javascript">
var inputs = document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
if (i % 2 == 0) {
inputs[i].outerHTML+='<br/>' ;
}
}
</script>
Upvotes: 1
Reputation: 1362
Replace this line
inputs[i].appendChild(mybr);
with (by using Jquery)
$(inputs[i]).after(mybr)
but if you want to use Javascript I will refer to see this Answer
Upvotes: 0