Advertisement
sotatop

Changing HTML Text

Feb 18th, 2012
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.60 KB | None | 0 0
  1. <!-- Replacing selected text via html tags -->
  2.  
  3. <html>
  4. <body>
  5.     <!-- Button -->
  6.     <!-- Put function name in onClick -->
  7.     <input type="button" value="Click me!" onClick="changeText()" />
  8.    
  9.     <!-- You must use an id for the javascript to fetch, here we are using a "p" tag -->
  10.     <!-- Put original text in here  -->
  11.     <p id="test">This is a test.</p>
  12.    
  13.     <!-- Code -->
  14.     <script type="text/javascript">
  15.         function changeText(){
  16.             document.getElementById("test").innerHTML = "This is not a test";
  17.         }
  18.     </script>
  19.  
  20.     <!-- Here, we have successfully changed "This is a test" into "This is not a test" -->
  21. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement