0

I am trying to create a jquery slider, but jquery-ui css is not being applied to a div at all. Any help will be appreciated!

var dummy = document.createElement('div')
dummy.innerHTML = 'dummy'

var wRange = document.createElement('div')
wRange.setAttribute('id', 'range')
wRange.classList.add('cntr')

$("#range").slider({
  range: "min",
  min: 0,
  max: 999,
  value: 50,
  slide: function(e, ui) {
    return $(".ui-slider-handle").html(ui.value)
  }
})

$(".ui-slider-handle").html("50")

document.body.appendChild(dummy)
document.body.appendChild(wRange)

Here is : fiddle

1 Answer 1

2

You're selecting elements

$("#range")slider({...});
$(".ui-slider-handle").html("50");

before they appended to body, so jQuery can't find them in a DOM.

Do that:

document.body.appendChild(dummy)
document.body.appendChild(wRange)

$("#range").slider({
  range: "min",
  min: 0,
  max: 999,
  value: 50,
  slide: function(e, ui) {
    return $(".ui-slider-handle").html(ui.value)
  }
})

$(".ui-slider-handle").html("50")

Or jQuery style way:

var dummy = $('<div>').html('dummy');

var wRange = $('<div>')
    .attr('id','range')
    .addClass('cntr')
    .slider({
        range: "min",
        min: 0,
        max: 999,
        value: 50,
        slide: function(e, ui) {
            return $(".ui-slider-handle").html(ui.value)
        }
    });

$(document.body).append(dummy, wRange);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.