+ 1

Can i replace two strings with one string simultaneously located in different id

..

27th Mar 2018, 11:06 AM
Sachin Kumar
Sachin Kumar - avatar
2 Answers
+ 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");
27th Mar 2018, 5:08 PM
Adam
Adam - avatar
0
Thanks it worked
27th Mar 2018, 6:42 PM
Sachin Kumar
Sachin Kumar - avatar