Kenny Smith
Kenny Smith

Reputation: 889

Creating a dynamic slider jQuery

I am trying to create a slider using jQuery. This is my code:

function createSlider(label_value, input_id, output_id, minValue, maxValue, initialValue, step) {
    const div = $("<div/>");
    const input = ($`<input type="range" min="${minValue}" max="${maxValue}" step="${step}" id="${input_id}" value="${initialValue}"/>`);
    div.append(input);

    return div;
}

But on this line: "div.append(input);", I am getting the error :"Uncaught TypeError: Cannot read property 'ownerDocument' of undefined". What am I doing wrong?

Upvotes: 0

Views: 113

Answers (1)

Romi Halasz
Romi Halasz

Reputation: 2009

There seems to be a problem with this line:

const input = ($`<input type="range" min="${minValue}" max="${maxValue}" step="${step}" id="${input_id}" value="${initialValue}"/>`);

You should replace the $ with the starting parenthesis:

const input = $(`<input type="range" min="${minValue}" max="${maxValue}" step="${step}" id="${input_id}" value="${initialValue}"/>`);

Hope this helps.

Upvotes: 1

Related Questions