Let\'s say you have a .click()
call. What code could you write inside of that .click()
call so that each time you click the selected element, you c
Try something along these lines:
$element.bind('click', function() {
$(this).html($(this).html() == 'string1' ? 'string2' : 'string1');
});
Edit - 2020-01-28
Note that bind()
is now deprecated. You should be using on()
instead, as of jQuery 1.7+:
$element.on('click', function() {
$(this).text((i, t) => t == 'string1' ? 'string2' : 'string1');
});