0

I want to add a button to the right of some text. Both the text were added using JS DOM. I researched a lot, but couldn't place it there. It always goes to the next line. How do I do this?

var text = document.createElement("h4");
var content = document.createTextNode("Insert buttton here:--> ");
text.appendChild(content);

document.body.appendChild(text);


var btn = document.createElement("BUTTON");
btn.textContent = "Place me right of the -->";

document.body.appendChild(btn);
html {
  font-size: 29px;
}
<html>

<head></head>

<body>

</body>

</html>

Thanks in advance for your time and consideration.

2 Answers 2

3

You can add the button to an inner html of h4.

var btn = document.createElement("BUTTON");
btn.textContent = "Place me right of the -->";
var text = document.createElement("h4");
text.innerHTML = "Insert buttton here:-->" + btn.outerHTML;

document.body.appendChild(text);
html {
  font-size: 29px;
}
<html>

<head></head>

<body>

</body>

</html>

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

Comments

1

Just append the button to the h4 ?

var text = document.createElement("h4");
var content = document.createTextNode("Insert buttton here:--> ");
text.appendChild(content);

var btn = document.createElement("BUTTON");
btn.textContent = "Place me right of the -->";

text.appendChild(btn);

document.body.appendChild(text);
html {
  font-size: 29px;
}
<html>

<head></head>

<body>

</body>

</html>

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.