javascript - How do I make an OnClick function that will change a word when a user clicks it to another word? -
okay so, want make onclick
function in javascript makes when user clicks on it, change word. there replaceword()
function or let me so? know not real code, example:
<p>quickly <span onclick="replaceword('surf');">search</span> web!</p>
if there is, can tell me how reverse code maybe? when click on second time, change "search"?
no, there isn't native function, can create on own.
function replaceword(that, word, oword) { that.textcontent = that.textcontent == oword ? word : oword; }
you can call this:
<p>quickly<span onclick="replaceword(this,'surf','search');">search</span>the web!</p>
live demo: http://jsfiddle.net/t6bva/6
Comments
Post a Comment