I've tried using textContent and innerHTML, but haven't been able to change hello world to goodbye.
<div data-test='hello'>
hello world
</div>
var test = document.querySelectorAll("[data-test='hello']");
//test.textContent = "goodbye";
test.innerHTML = "goodbye";
Definition by documentation: The querySelectorAll() method returns all elements in the document that matches a specified CSS selector(s), as a static NodeList object.
The querySelectorAll
method return an array
, then you can change the first element as follow:
var test = document.querySelectorAll('[data-test="hello"]');
test[0].innerHTML = "goodbye";
<div data-test='hello'>
hello world
</div>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments