0

I'm trying to call percentValue from CSS #number1 and have it run in the function in place of the absolute number which can usually be found after "percent":. I'm not really sure how it works and any help would be amazing.

(function($) {
    $(function() {
        var percentValue = document.getElementById('number1');
        /* thermometers with config */
        $('.thermometer').thermometer({
            percent: percentValue, 
            speed: 'slow'
        })
    });
})(jQuery);

Updated Code (Answered)

(function($) {
  $(function() {
           var percentValue = $('#number1').text()

    /* thermometers with config */
    $('.thermometer').thermometer({
      percent: percentValue,
      speed: 'slow'
    })
  });
})(jQuery);

3
  • try document.getElementById('number1') .value Commented Mar 8, 2016 at 15:48
  • What type of element is #number1? You should select it via jQuery ($('#number1')) and use either val() or text() on it. Currently you're passing percent a DOMElement which isn't going to work. Also note the closure is redundant in this case. Commented Mar 8, 2016 at 15:48
  • Thanks Rory, I had done it in JQuery before and hadn't worked, now i see it was the redundant closure on the .text() that was messing it up. Cheers! Commented Mar 8, 2016 at 16:14

1 Answer 1

1

var percentValue = document.getElementById('number1'); Currently this code is selecting the HTML element not the value it contains

Assuming number1 is a textbox or something, you can do: var percentValue = document.getElementById('number1').value; or (using jQuery): var percentValue = $("#number1").val();

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.