+ 4
how when the button is double-clicked or more it will return to the first or second text,
whether to use the if else statement and how to apply it to my jquery code this time https://code.sololearn.com/W8yYOs6FsXBN/?ref=app
4 Réponses
+ 4
Try this on JS section:
var texts=["first text", "second text", "third text"];
var index=0;
$(function() {
$("#a").click(function() {
index > 1 ? index = 0 : index++;
$("#test").text(texts[index]);
});
});
Adjust `index > 1` to the highest array index minus one, in here we have 3 string, the highest array index was 2, that's why the `index > 1`.
+ 4
whether the writing in the array can take from html
+ 3
Example:
var x = document.getElementById("test');
but it doesn't appear
+ 3
document.getElementById("test") should exist tag <div id="test"></div> in HTML. It does not appear because maybe there's no tag div, wrong id name, or maybe wrong link or no link if that code is in JS external file. That's all i know :)