Skip to content

Instantly share code, notes, and snippets.

@01-Scripts
Created March 12, 2010 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 01-Scripts/330530 to your computer and use it in GitHub Desktop.
Save 01-Scripts/330530 to your computer and use it in GitHub Desktop.
JS: Changing Text with innerHTML
// Changing Text with innerHTML
// http://www.tizag.com/javascriptT/javascript-innerHTML.php
<script type="text/javascript">
function changeText(){
document.getElementById('boldStuff').innerHTML = 'Fred Flinstone';
}
</script>
<p>Welcome to the site <b id='boldStuff'>dude</b> </p>
<input type='button' onclick='changeText()' value='Change Text'/>
//Changing HTML with innerHTML
<script type="text/javascript">
function changeText3(){
var oldHTML = document.getElementById('para').innerHTML;
var newHTML = "<span style='color:#ffffff'>" + oldHTML + "</span>";
document.getElementById('para').innerHTML = newHTML;
}
</script>
<p id='para'>Welcome to the site <b id='boldStuff3'>dude</b> </p>
<input type='button' onclick='changeText3()' value='Change Text'/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment