2

I want to break and center after each button, any suggestions? setAttribute did not work and does not add the breaks

for (var j = 0; j <= 6; j++) {
  var btn = document.createElement("BUTTON");
  var t = document.createTextNode(sm[j] + " " + sy[j]);
  btn.appendChild(t);
  document.body.appendChild(btn);
}

1

1 Answer 1

0

jsfiddle

HTML

<div id='theParent' class='center_the_stuff'>

</div>

JS

function addInput(type, value, name, id, onclick, parentId) {
    //Create an input type dynamically.   
    var element = document.createElement("input");
    //Assign different attributes to the element. 
    element.type = type;
    element.value = value; // Really? You want the default value to be the type string?
    element.name = name; // And the name too?
    element.id = id;
    element.onclick = onclick;

    var parent = document.getElementById(parentId);
    //Append the element in page (in span).  
    parent.appendChild(element);
}

function addBreak(parentId) {
    var br = document.createElement("br");
    var parent = document.getElementById(parentId);
    parent.appendChild(br);
}

window.onload = function () {
    for (var j = 0; j <= 6; j++) {
        var temp = 'mybutton' + j;
        addInput('button', temp, temp, temp, undefined, 'theParent');
        addBreak('theParent');
    }
}

CSS

.center_the_stuff {
    text-align: center;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.