Peter
New Member
God
Posts: 6
|
Post by Peter on Jun 18, 2004 11:44:20 GMT
Using Replace FunctionThe replace function is used to change switch something in a document or form or something. Usually it changes the HTML of a document or the innerHTML of a tag. Sometimes it’s used to change the outer HTML. Anyways, I’m gonna make like Peter and do a simple code and explain it. Any questions after that I will be willing to answer. I’m going to do something simple and switch “Hey,” into “Hello,” <script> <!-- var welcome = document.getElementsByTagName(‘td’)[2]; welcome.innerHTML = welcome.innerHTML.replace(‘Hey,’,’Hello’); //-> </script> First we are declaring welcome as the third <TD> in the document. Next we are saying that the HTML inside the tag (innerHTML) is now going to be equal to the text inside the tag but with the “Hey,” replaced with “Hello,”. So basically you are just changing what is in the first tag to what’s in the first tag and making it show that way on the page. You can just wipe out something by doing something like this: welcome.innerHTML=welcome.innerHTML.replace(‘Hey,’,’’); Now, I’m challenging you guys to completely change the text within the welcome TD. Whoever does it gets a cookie point or some tutoring lesson thingymabob. Note: You might notice that I didn't include an if statement to see if the person was logged in or not. Well with replace, if what you are trying to replace isn't there, then nothing happens.Tutorial By: Forte
|
|