javascript – Creating a dynamic slider jQuery-ThrowExceptions

Exception or error:

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?

How to solve:

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.

Leave a Reply

Your email address will not be published. Required fields are marked *