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.

1
  • @Mamun this won't work. it gives the whole tag as string and shows as it is Commented May 17, 2018 at 15:45

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you, this helped. I now feel so dumb. i tried adding innerHTML after the value. Thank you so much
@Lucian great! Glad i could help. Tick it if it helped :)
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 = ...;

Comments

2

Did you try this solution?

output.innerHTML = `${value} <span class="my-class">mm</span>`;

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.