Created
March 12, 2010 17:05
-
-
Save 01-Scripts/330530 to your computer and use it in GitHub Desktop.
JS: Changing Text with innerHTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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