Немного отредактировал, так как в вашем коде было много проблем. У идентификатора контейнера была опечатка, кнопка была создана с помощью button_container, который на самом деле является идентификатором et c. Ниже вы можете увидеть, как создается кнопка.
CreateElement:
В createElement мы должны указать имя тега, а не сам идентификатор создаваемого нового элемента html. Подробнее здесь .
document.createElement('button'); //p tag, h1,h2,h3 tags etc, divs
SetAttribute:
Для идентификатора мы используем setAttribute , который устанавливает значение атрибут указанного элемента. Если атрибут уже существует, значение обновляется; в противном случае добавляется новый атрибут с указанным именем и значением.
btn.setAttribute("id", "button_content"); //Ids,classes and data-attribute
//id="myid", class="myclass", data-myid=1
InnerText:
Наконец, для значения мы используем innerText установить текст кнопки и вызвать его onLoad.
btn.innerText ="Click me";
Полный код:
<!DOCTYPE html>
<html>
<head>
<title>Website Project</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<style>
Toggle_bold {
font: bold;
}
.Toggle_width{
width: 50%;
}
.Toggle_width{
color: #ff2800;
}
.Toggle_size{
font-size: 100%;
}
#button_containter{
display: flex;
align-items: center;
justify-content: center;
text-align: center;
}
</style>
</head>
<body>
<div id ="button_container"></div>
<script>
function createButton (name){
const btn = document.createElement('button'); //Add button with create Element
btn.setAttribute("id", "button_content"); //Add Id with setAttribute method
btn.innerText ="Click me";// Add value of the button with innerText property
let container = document.getElementById("button_container"); //Fetch container div
console.log(btn);
console.log(container);
container.appendChild(btn); //Append button to it.
}
function makeBold(){
// changing the size to bold, getting it from CSS s
this.p.classList.toggle("Toggle_bold");
}
function changedWidth(){
this.p.classList.toggle('Toggle_width');
}
function changeColor(){
this.p.classList.toggle('Toggle_width');
}
function changeSize(){
this.p.classList.toggle('Toggle_size');
}
window.onload = () => {
createButton();// call button function here to create the button
}
</script>
</body>
</html>
Наконец, я считаю, что мы учимся на практике, и поэтому я надеюсь, что это помогло очистить некоторые из путаницы, а также решение вашей проблемы:).