javascript - DOM scripting: create elements and position them on one line -
A small background information for my page:
I have a section that contains an input The field below has an "add" button that creates more input fields. Only one field is needed on the screen, the latter fields have a "delete" button that removes the relevant input field.
Here's a screen shot:
As you can see the "-" buttons located after each input box, I need them to just go right. Trying to: "" - "" / Delete buttons not inline on
Code:
addField function (count) {if (count & lt; = 4) {Count ++; Var id = "tag" + count; var newField = document.createElement ("Input"); newField.setAttribute ('type', 'text'); newField.setAttribute ('class', 'field'); NewField.setAttribute ('id', id); Var location = document.getElementById ("tag"); inputContainer.appendChild (Newfield); Var removeId = "remove" + count; Var remove = document.createElement ("input"); Remove.setAttribute ("type", "button"); Remove.setAttribute ("value", "-"); remove.setAttribute ('class', 'remove'); Remove.setAttribute ('id', removeId); Remove.onclick = function () {var targetInput = document.getElementById (ID); Var targetRemove = document.getElementById (extract ID); TargetInput.remove (); TargetRemove.remove (); }; inputContainer.appendChild (to remove); Calculation of return; }}
You have two options:
-
place each line in your & lt; Div & gt; : -
after each line & lt; Br> Keep & lt; Input type = "text" & gt; & Lt; Button & gt; - & lt; / Button & gt; & Lt; Br> Div & gt; must be tagged within, within For the second, you can add all your elements as you make them, just & lt; Br> Add elements.
var div = document.createElement ('div'); var input = document.createElement ('input'); Var button = document.createElement ('button'); button. Winner Lesson = '-'; Div.appendChild (input); Div.appendChild (button); inputContainer.appendChild (div); The demo is showing both examples:
Comments
Post a Comment