+ 1
Can i replace two strings with one string simultaneously located in different id
..
2 ответов
+ 1
To be clear, you have something like:
<p id="foo">Some text here</p>
<p id="bar">Different text</p>
And you want to replace both of those with "this new text" correct?
what you want is document.querySelectorAll().
It returns an array of nodes that match the selectors.
var nodes = document.querySelectorAll("#foo, #bar");
for(var i = 0; i < nodes.length; i++) {
nodes[i].innerHTML = "this new text";
}
If you use the jQuery library this becomes even simpler:
$("#foo, #bar").html("this new text");
0
Thanks it worked