ComeDown ComeDown - 5 months ago 10
Javascript Question

Access to a value within the span tag

I'm trying to modify this range slider.
Since I have to incorporate this slider in another file I need to understand how it works.
In particular I would like to know where the code returns the selected year.

I tried adding these prints but it doesn't print the correct year.

var rangeSlider = function() {
var slider = $('.range-slider');
var range = $('.range-slider__range');
var value = $('.range-slider__value');

// added print
console.log(value);

slider.each(function() {
value.each(function() {
var value = $(this).prev().attr('value');
$(this).html(value);

// added print
console.log(value);
console.log(value.innerHMTL);
console.log(value.innerText);
});

range.on('input', function() {
$(this).next(value).html(this.value);
});
});
};

rangeSlider();


Looking on Chrome, I see that the value being edited is in
span
.
enter image description here
I can't access to that value. How can I do that?

Thanks

Answer

The content of an element can be accessed using text() method. For example:

$('#your_element').text();