0
var $document = $(document);
var selector = '[data-rangeslider]';
var $element = $(selector);
// For ie8 support
var textContent = ('textContent' in document) ? 'textContent' : 'innerText';
// Example functionality to demonstrate a value feedback
function valueOutput(element) {
    var value = element.value;
    var output = element.parentNode.getElementsByTagName('output')[0] || element.parentNode.parentNode.getElementsByTagName('output')[0];
    output[textContent] = value + 'mm';
}
$document.on('input', 'input[type="range"], ' + selector, function(e) {
    valueOutput(e.target);
});

in the line output[textContent] = value + 'mm'; I need the output as value + '<span class="classname">mm</span>' I tried most of the things and did a lot of research but no luck so far.

This might be something very simple but I am too new to JavaScript so couldn't figure it out.

halfer
  • 19,824
  • 17
  • 99
  • 186
Lucian
  • 1,715
  • 3
  • 17
  • 26

3 Answers3

4

You should change this line:

output[textContent] = value + 'mm';

to:

output.innerHTML = value + '<span>mm</span>';

Also, you could remove the IE8 fallback, as it will not be necessary. All browsers have support for innerHTML.

In your code you are assigning the node text and not the node HTML as you should.

You can read more about the difference between innerText and innerHTML here.

muecas
  • 4,265
  • 1
  • 8
  • 18
2

Did you try this solution?

output.innerHTML = `${value} <span class="my-class">mm</span>`;
2
var textContent = ('textContent' in document) ? 'textContent' : 'innerText';

textContent and innerText are both functions for adding text to an element you want to use innerHTML to add HTML.

Like this:

ouput.innerHTML = ...;
barro32
  • 2,559
  • 23
  • 36