Quote:
Originally Posted by starling
Code:
<p>So this would be the paragraph and<span id="your_paragraph">THIS</span>is the word to be changed</p>
INPUT HERE: <input type="text" id="theText" />
<input type="button" id="btn" value="Update" />
<script>
var span = document.getElementById('your_paragraph');
var btn = document.getElementById('btn');
var txt = document.getElementById('theText');
btn.onclick = function(){
span.textContent = txt.value;
};
</script>
The problem is it only works on one element instead of multiple. Is there a way to make it change all instances of the word to the same input, if I had multiple paragraphs?
|
You would need to go through all elements that can contain the word to be replaced and replace each one individually I would think.
.