JQuery -- I want to click a word to change it then click it again to change it back
jquery, switch-statement, toggle
Solution
$("#greeting").click(function(){
$(this).text(function(_, oldText) {
return oldText === 'Goodbye!' ? 'Hello!' : 'Goodbye!';
});
});
http://jsfiddle.net/DPeWk/
Problem
I want users to be able to click on 'Hello!' to make it change to 'Goodbye!' and then click it again to change it back to 'Hello!'. I've got as far as making 'Hello!' change to 'Goodbye!', but I don't know how to make the function 'repeat'. I'm an extreme novice at this, so all help and advice is welcome! This is as far as I've got: HTML: ``` <body> <p id = "greeting">Hello!</p> </body> ``` JQuery: ``` $(function(){ $("#greeting").click(function(){ $(this).text('Goodbye!').toggle(hide); }); }); ```