NeedHate NeedHate - 4 months ago 5
jQuery Question

How to get each of objects in list on click

I have list of questions.
And I have a html, f.e., . Each click, changes html ".title" with a next question from objects.
Click on button, I get: "Is it good to be me?",
next click, I get: "Who is the best man?" and so on...

var questions = {
first: "Is it good to be me?",
second: "Who is the best man?",
third: "Do you believe?",
fourth: "Are you sexy?"
var txt = "";
var x;

for(x in questions) {
txt += questions[x] + "<br>";


You can use array instead of object.

var questions = [
    "Is it good to be me?",
    "Who is the best man?",
    "Do you believe?",
    "Are you sexy?"

var index = 0;
<script src=""></script>
<button>Get question</button>

To getting index of question, use index variable. Also you can use data-index attribute to do this.