+ 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

17th May 2019, 8:36 PM
Avirur Rahman
Avirur Rahman - avatar
4 Answers
+ 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`.
17th May 2019, 8:57 PM
Ipang
+ 4
whether the writing in the array can take from html
17th May 2019, 9:12 PM
Avirur Rahman
Avirur Rahman - avatar
+ 3
Example: var x = document.getElementById("test'); but it doesn't appear
17th May 2019, 9:16 PM
Avirur Rahman
Avirur Rahman - avatar
+ 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 :)
18th May 2019, 4:54 AM
Rizki Rivaldi