forum

Home / DeveloperSection / Forums / How to call function with variable as paramenter in jquery?

How to call function with variable as paramenter in jquery?

Jayden Bell225218-Mar-2015

I want to call the function fill() with a variable as parameter. Everytime next() is called, the number of the variable should increase. So first, fill( q1 ) is called, then fill( q2 ) and so on. But apparently, you can't use variables as parameters. Any ideas?

var q1 = [2, "ff", "dd", "ss", "hh"];
    var q2 = [2, "ff", "dd", "ss", "hh"];
 
    var fill = function (data) {
        $("#number").html(data[1]);
        $("#cat").html(data[2]);
        $("#ques span").html(data[3]);
        $("#answ .answ:nth-child(1) button").html(data[4]);
        $("#answ .answ:nth-child(2) button").html(data[5]);
        $("#answ .answ:nth-child(3) button").html(data[6]);
        $("#answ .answ:nth-child(4) button").html(data[7]);
        $("#answ .answ:nth-child(" + data[0] + ") button").attr("data-state", "correct");
    }
    var count = 1;
    function next() {
        fill("q" + count);
        count++;
    }

Updated on 18-Mar-2015

Can you answer this question?


Answer

1 Answers

Liked By