4

I am trying to add a bootstrap button into a row dynamically. Below is my code. A button is added but it is not bootstrap style.

var cell4 = row.insertCell(3);
var element3 = document.createElement("input");
element3.type = "button";
element3.name = "add";
element3.value="Remove";
element3.class="btn btn-danger btn-xs";
cell4.appendChild(element3);

Can someone tell the right way to do it? Thanks.

2 Answers 2

3

This would be because element3.class is not a valid property.

You should be using element3.className="btn btn-danger btn-xs" instead

Sign up to request clarification or add additional context in comments.

1 Comment

Mark answer as correct if this solved your question, thanks :)
1

You should refer className property instead of class property.

function myFunc()
{
  var cell4 = document.getElementById('insertHere');
var element3 = document.createElement("input");
element3.type = "button";
element3.name = "add";
element3.value="Remove";
element3.className="btn btn-danger btn-xs";
cell4.appendChild(element3);
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css" rel="stylesheet"/>

<div id="insertHere"> </div>
<input type="button" value="addButton" onclick="myFunc()" />

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.