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

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -