Your question leaves a lot of information to the imagination, but for instance this will swap those two words, once a second, in an element with the id
"target"
:
var target = $("#target"),
word = target.text();
setInterval(function() {
word = word === "hello" ? "glad" : "hello";
target.text(word);
}, 1000);
Or if you want somthing a bit fancier looking, throw in a fade:
var target = $("#target"),
word = target.text();
setInterval(function() {
word = word === "hello" ? "glad" : "hello";
target.fadeOut('fast', function() {
target.text(word).fadeIn('fast');
});
}, 1000);
1
solved how to switch between two different texts in jquery..? [closed]