I cant find how to do this or know the terminology so excuse me if this may be a duplicate.
How do I take a variable and add something like this to it:
<code>let x = document.createElement("div");
x.add("Hello world!")
//Let's say the ".add" thing is an inner text function that just gives div the inner text of, in this case, Hello world.
</code>
<code>let x = document.createElement("div");
x.add("Hello world!")
//Let's say the ".add" thing is an inner text function that just gives div the inner text of, in this case, Hello world.
</code>
let x = document.createElement("div");
x.add("Hello world!")
//Let's say the ".add" thing is an inner text function that just gives div the inner text of, in this case, Hello world.
How do I do this as JS libraries do? Even if my example needs to be changed to make it work.
New contributor
Westberg Personal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4
There’s a textContent property that you can get and set.
<code>document.querySelector(".example").textContent += " | New Text";</code>
<code>document.querySelector(".example").textContent += " | New Text";</code>
document.querySelector(".example").textContent += " | New Text";
<code><div class="example">Original Text</div></code>
<code><div class="example">Original Text</div></code>
<div class="example">Original Text</div>
1