Trying to convert a numeric value to css












1














I am trying to iterate over a number of DIVS, pull a numeric value from said DIVs, if that value is == to a specific value in the JS, apply a specific CSS Class back to the DIV it came from.



This is the code I have so far



const getRating = document.getElementsByClassName('my-ratings');
let getRatingValues = ;
for(var i = 0; i < getRating.length; i++) {
getRatingValues += getRating[i].textContent;

if (getRatingValues == 5) {
getRating.classList.add('rating-5');
}
if (getRatingValues == 4) {
getRating.classList.add('rating-4');
}
if (getRatingValues == 3) {
getRating.classList.add('rating-3');
}
if (getRatingValues == 2) {
getRating.classList.add('rating-2');
}
if (getRatingValues == 1) {
getRating.classList.add('rating-1');
}
}


I feel like I am close, but just can't break the back of it...



At the moment, the script seems to fill the getRatingValues as a string, so if I have values of 5, 3, 1, 2, 2, 4 the getRatingValues will be 531224. Could someone point me in the right direction please?










share|improve this question


















  • 5




    += does not add elements to an array. You want getRatingValues.push(...). Once you fix that, things still don't make sense; why is it an array in the first place? What are you trying to do?
    – Pointy
    Nov 19 '18 at 16:02












  • why you define getRatingValues as an array but use it as an integer? thats not clear :) And you can save many space if you write your code dynamical like: getRating.classList.add('rating-' + getRatingValues);
    – episch
    Nov 19 '18 at 16:04










  • += also does something different when the operators are strings (and textContent is a string).
    – Sergiu Paraschiv
    Nov 19 '18 at 16:04










  • Why are you adding a string to an array?
    – epascarello
    Nov 19 '18 at 16:05










  • I am collecting the values from the DIV with class my-ratings, I am then transforming that value into a CSS Class, so if the DIV has text in it that is 3, I generate a css class called ratings-3 and apply it to the DIV
    – Takuhii
    Nov 19 '18 at 16:23
















1














I am trying to iterate over a number of DIVS, pull a numeric value from said DIVs, if that value is == to a specific value in the JS, apply a specific CSS Class back to the DIV it came from.



This is the code I have so far



const getRating = document.getElementsByClassName('my-ratings');
let getRatingValues = ;
for(var i = 0; i < getRating.length; i++) {
getRatingValues += getRating[i].textContent;

if (getRatingValues == 5) {
getRating.classList.add('rating-5');
}
if (getRatingValues == 4) {
getRating.classList.add('rating-4');
}
if (getRatingValues == 3) {
getRating.classList.add('rating-3');
}
if (getRatingValues == 2) {
getRating.classList.add('rating-2');
}
if (getRatingValues == 1) {
getRating.classList.add('rating-1');
}
}


I feel like I am close, but just can't break the back of it...



At the moment, the script seems to fill the getRatingValues as a string, so if I have values of 5, 3, 1, 2, 2, 4 the getRatingValues will be 531224. Could someone point me in the right direction please?










share|improve this question


















  • 5




    += does not add elements to an array. You want getRatingValues.push(...). Once you fix that, things still don't make sense; why is it an array in the first place? What are you trying to do?
    – Pointy
    Nov 19 '18 at 16:02












  • why you define getRatingValues as an array but use it as an integer? thats not clear :) And you can save many space if you write your code dynamical like: getRating.classList.add('rating-' + getRatingValues);
    – episch
    Nov 19 '18 at 16:04










  • += also does something different when the operators are strings (and textContent is a string).
    – Sergiu Paraschiv
    Nov 19 '18 at 16:04










  • Why are you adding a string to an array?
    – epascarello
    Nov 19 '18 at 16:05










  • I am collecting the values from the DIV with class my-ratings, I am then transforming that value into a CSS Class, so if the DIV has text in it that is 3, I generate a css class called ratings-3 and apply it to the DIV
    – Takuhii
    Nov 19 '18 at 16:23














1












1








1







I am trying to iterate over a number of DIVS, pull a numeric value from said DIVs, if that value is == to a specific value in the JS, apply a specific CSS Class back to the DIV it came from.



This is the code I have so far



const getRating = document.getElementsByClassName('my-ratings');
let getRatingValues = ;
for(var i = 0; i < getRating.length; i++) {
getRatingValues += getRating[i].textContent;

if (getRatingValues == 5) {
getRating.classList.add('rating-5');
}
if (getRatingValues == 4) {
getRating.classList.add('rating-4');
}
if (getRatingValues == 3) {
getRating.classList.add('rating-3');
}
if (getRatingValues == 2) {
getRating.classList.add('rating-2');
}
if (getRatingValues == 1) {
getRating.classList.add('rating-1');
}
}


I feel like I am close, but just can't break the back of it...



At the moment, the script seems to fill the getRatingValues as a string, so if I have values of 5, 3, 1, 2, 2, 4 the getRatingValues will be 531224. Could someone point me in the right direction please?










share|improve this question













I am trying to iterate over a number of DIVS, pull a numeric value from said DIVs, if that value is == to a specific value in the JS, apply a specific CSS Class back to the DIV it came from.



This is the code I have so far



const getRating = document.getElementsByClassName('my-ratings');
let getRatingValues = ;
for(var i = 0; i < getRating.length; i++) {
getRatingValues += getRating[i].textContent;

if (getRatingValues == 5) {
getRating.classList.add('rating-5');
}
if (getRatingValues == 4) {
getRating.classList.add('rating-4');
}
if (getRatingValues == 3) {
getRating.classList.add('rating-3');
}
if (getRatingValues == 2) {
getRating.classList.add('rating-2');
}
if (getRatingValues == 1) {
getRating.classList.add('rating-1');
}
}


I feel like I am close, but just can't break the back of it...



At the moment, the script seems to fill the getRatingValues as a string, so if I have values of 5, 3, 1, 2, 2, 4 the getRatingValues will be 531224. Could someone point me in the right direction please?







javascript css






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 16:01









Takuhii

1721217




1721217








  • 5




    += does not add elements to an array. You want getRatingValues.push(...). Once you fix that, things still don't make sense; why is it an array in the first place? What are you trying to do?
    – Pointy
    Nov 19 '18 at 16:02












  • why you define getRatingValues as an array but use it as an integer? thats not clear :) And you can save many space if you write your code dynamical like: getRating.classList.add('rating-' + getRatingValues);
    – episch
    Nov 19 '18 at 16:04










  • += also does something different when the operators are strings (and textContent is a string).
    – Sergiu Paraschiv
    Nov 19 '18 at 16:04










  • Why are you adding a string to an array?
    – epascarello
    Nov 19 '18 at 16:05










  • I am collecting the values from the DIV with class my-ratings, I am then transforming that value into a CSS Class, so if the DIV has text in it that is 3, I generate a css class called ratings-3 and apply it to the DIV
    – Takuhii
    Nov 19 '18 at 16:23














  • 5




    += does not add elements to an array. You want getRatingValues.push(...). Once you fix that, things still don't make sense; why is it an array in the first place? What are you trying to do?
    – Pointy
    Nov 19 '18 at 16:02












  • why you define getRatingValues as an array but use it as an integer? thats not clear :) And you can save many space if you write your code dynamical like: getRating.classList.add('rating-' + getRatingValues);
    – episch
    Nov 19 '18 at 16:04










  • += also does something different when the operators are strings (and textContent is a string).
    – Sergiu Paraschiv
    Nov 19 '18 at 16:04










  • Why are you adding a string to an array?
    – epascarello
    Nov 19 '18 at 16:05










  • I am collecting the values from the DIV with class my-ratings, I am then transforming that value into a CSS Class, so if the DIV has text in it that is 3, I generate a css class called ratings-3 and apply it to the DIV
    – Takuhii
    Nov 19 '18 at 16:23








5




5




+= does not add elements to an array. You want getRatingValues.push(...). Once you fix that, things still don't make sense; why is it an array in the first place? What are you trying to do?
– Pointy
Nov 19 '18 at 16:02






+= does not add elements to an array. You want getRatingValues.push(...). Once you fix that, things still don't make sense; why is it an array in the first place? What are you trying to do?
– Pointy
Nov 19 '18 at 16:02














why you define getRatingValues as an array but use it as an integer? thats not clear :) And you can save many space if you write your code dynamical like: getRating.classList.add('rating-' + getRatingValues);
– episch
Nov 19 '18 at 16:04




why you define getRatingValues as an array but use it as an integer? thats not clear :) And you can save many space if you write your code dynamical like: getRating.classList.add('rating-' + getRatingValues);
– episch
Nov 19 '18 at 16:04












+= also does something different when the operators are strings (and textContent is a string).
– Sergiu Paraschiv
Nov 19 '18 at 16:04




+= also does something different when the operators are strings (and textContent is a string).
– Sergiu Paraschiv
Nov 19 '18 at 16:04












Why are you adding a string to an array?
– epascarello
Nov 19 '18 at 16:05




Why are you adding a string to an array?
– epascarello
Nov 19 '18 at 16:05












I am collecting the values from the DIV with class my-ratings, I am then transforming that value into a CSS Class, so if the DIV has text in it that is 3, I generate a css class called ratings-3 and apply it to the DIV
– Takuhii
Nov 19 '18 at 16:23




I am collecting the values from the DIV with class my-ratings, I am then transforming that value into a CSS Class, so if the DIV has text in it that is 3, I generate a css class called ratings-3 and apply it to the DIV
– Takuhii
Nov 19 '18 at 16:23












4 Answers
4






active

oldest

votes


















3














DRY - and cast to number:



let getRatingValues = 0;
document.querySelectorAll('.my-ratings').forEach(function(rate) { // for each my rating
let val = rate.textContent; // get the rate
getRatingValues += isNaN(val)?0:+val; // convert to number if is IS a number and add
rate.classList.add('rating-'+val); // add the class - here or outside the loop?
})


I would have thought getRating.classList.add('rating-'+val); should be outside the loop since now you will get 5 classes on one div if all 5 are set



For IE you need



var ratings = document.querySelectorAll('my-ratings');
for (var i=0;i<ratings.length;i++) {
let val = ratings[i].innerText, rate = ratings[i];





share|improve this answer























  • Ok, updated.....
    – mplungjan
    Nov 19 '18 at 16:09










  • This is really tidy, but I am getting document.getElementsByClassName('my-ratings').forEach is not a function
    – Takuhii
    Nov 19 '18 at 16:21










  • Please see update. I changed to use querySelectorAll and IE does not like forEach on nodes - I could have created a working example if I'd had the HTML
    – mplungjan
    Nov 19 '18 at 16:23












  • One more thing, getRating is now not defined, do I just create a const and place the document.querySelectorAll in it?
    – Takuhii
    Nov 19 '18 at 16:32










  • Ah no. I assume rate.classList.add
    – mplungjan
    Nov 19 '18 at 16:34



















1














You need to convert the string to Number.



Change



getRatingValues += getRating[i].textContent;


to



getRatingValues += Number(getRating[i].textContent);


Also, your getRatingValues should not be initialized to , instead it should be



let getRatingValues = 0;





share|improve this answer





















  • For completeness, it's probably worth mentioning you can cast the value to a number in a variety of different ways: += Number(var) or += parseInt(var) or, my favorite, += +var....
    – cale_b
    Nov 19 '18 at 16:07



















0














Like my comment you can optimize your code very easy:



that optimized Code:



const getRating = document.getElementsByClassName('my-ratings');
for(var i = 0; i < getRating.length; i++) {
getRatingValues += Number(getRating[i].textContent);
if (getRatingValues !== undefined) {
getRating.classList.add('rating-' + i);
}
}





share|improve this answer





























    0














    Try parseInt



    getRatingValues += parseInt(getRating[i].textContent);


    Reference : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378452%2ftrying-to-convert-a-numeric-value-to-css%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      DRY - and cast to number:



      let getRatingValues = 0;
      document.querySelectorAll('.my-ratings').forEach(function(rate) { // for each my rating
      let val = rate.textContent; // get the rate
      getRatingValues += isNaN(val)?0:+val; // convert to number if is IS a number and add
      rate.classList.add('rating-'+val); // add the class - here or outside the loop?
      })


      I would have thought getRating.classList.add('rating-'+val); should be outside the loop since now you will get 5 classes on one div if all 5 are set



      For IE you need



      var ratings = document.querySelectorAll('my-ratings');
      for (var i=0;i<ratings.length;i++) {
      let val = ratings[i].innerText, rate = ratings[i];





      share|improve this answer























      • Ok, updated.....
        – mplungjan
        Nov 19 '18 at 16:09










      • This is really tidy, but I am getting document.getElementsByClassName('my-ratings').forEach is not a function
        – Takuhii
        Nov 19 '18 at 16:21










      • Please see update. I changed to use querySelectorAll and IE does not like forEach on nodes - I could have created a working example if I'd had the HTML
        – mplungjan
        Nov 19 '18 at 16:23












      • One more thing, getRating is now not defined, do I just create a const and place the document.querySelectorAll in it?
        – Takuhii
        Nov 19 '18 at 16:32










      • Ah no. I assume rate.classList.add
        – mplungjan
        Nov 19 '18 at 16:34
















      3














      DRY - and cast to number:



      let getRatingValues = 0;
      document.querySelectorAll('.my-ratings').forEach(function(rate) { // for each my rating
      let val = rate.textContent; // get the rate
      getRatingValues += isNaN(val)?0:+val; // convert to number if is IS a number and add
      rate.classList.add('rating-'+val); // add the class - here or outside the loop?
      })


      I would have thought getRating.classList.add('rating-'+val); should be outside the loop since now you will get 5 classes on one div if all 5 are set



      For IE you need



      var ratings = document.querySelectorAll('my-ratings');
      for (var i=0;i<ratings.length;i++) {
      let val = ratings[i].innerText, rate = ratings[i];





      share|improve this answer























      • Ok, updated.....
        – mplungjan
        Nov 19 '18 at 16:09










      • This is really tidy, but I am getting document.getElementsByClassName('my-ratings').forEach is not a function
        – Takuhii
        Nov 19 '18 at 16:21










      • Please see update. I changed to use querySelectorAll and IE does not like forEach on nodes - I could have created a working example if I'd had the HTML
        – mplungjan
        Nov 19 '18 at 16:23












      • One more thing, getRating is now not defined, do I just create a const and place the document.querySelectorAll in it?
        – Takuhii
        Nov 19 '18 at 16:32










      • Ah no. I assume rate.classList.add
        – mplungjan
        Nov 19 '18 at 16:34














      3












      3








      3






      DRY - and cast to number:



      let getRatingValues = 0;
      document.querySelectorAll('.my-ratings').forEach(function(rate) { // for each my rating
      let val = rate.textContent; // get the rate
      getRatingValues += isNaN(val)?0:+val; // convert to number if is IS a number and add
      rate.classList.add('rating-'+val); // add the class - here or outside the loop?
      })


      I would have thought getRating.classList.add('rating-'+val); should be outside the loop since now you will get 5 classes on one div if all 5 are set



      For IE you need



      var ratings = document.querySelectorAll('my-ratings');
      for (var i=0;i<ratings.length;i++) {
      let val = ratings[i].innerText, rate = ratings[i];





      share|improve this answer














      DRY - and cast to number:



      let getRatingValues = 0;
      document.querySelectorAll('.my-ratings').forEach(function(rate) { // for each my rating
      let val = rate.textContent; // get the rate
      getRatingValues += isNaN(val)?0:+val; // convert to number if is IS a number and add
      rate.classList.add('rating-'+val); // add the class - here or outside the loop?
      })


      I would have thought getRating.classList.add('rating-'+val); should be outside the loop since now you will get 5 classes on one div if all 5 are set



      For IE you need



      var ratings = document.querySelectorAll('my-ratings');
      for (var i=0;i<ratings.length;i++) {
      let val = ratings[i].innerText, rate = ratings[i];






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 20 '18 at 5:56

























      answered Nov 19 '18 at 16:07









      mplungjan

      86.8k20122181




      86.8k20122181












      • Ok, updated.....
        – mplungjan
        Nov 19 '18 at 16:09










      • This is really tidy, but I am getting document.getElementsByClassName('my-ratings').forEach is not a function
        – Takuhii
        Nov 19 '18 at 16:21










      • Please see update. I changed to use querySelectorAll and IE does not like forEach on nodes - I could have created a working example if I'd had the HTML
        – mplungjan
        Nov 19 '18 at 16:23












      • One more thing, getRating is now not defined, do I just create a const and place the document.querySelectorAll in it?
        – Takuhii
        Nov 19 '18 at 16:32










      • Ah no. I assume rate.classList.add
        – mplungjan
        Nov 19 '18 at 16:34


















      • Ok, updated.....
        – mplungjan
        Nov 19 '18 at 16:09










      • This is really tidy, but I am getting document.getElementsByClassName('my-ratings').forEach is not a function
        – Takuhii
        Nov 19 '18 at 16:21










      • Please see update. I changed to use querySelectorAll and IE does not like forEach on nodes - I could have created a working example if I'd had the HTML
        – mplungjan
        Nov 19 '18 at 16:23












      • One more thing, getRating is now not defined, do I just create a const and place the document.querySelectorAll in it?
        – Takuhii
        Nov 19 '18 at 16:32










      • Ah no. I assume rate.classList.add
        – mplungjan
        Nov 19 '18 at 16:34
















      Ok, updated.....
      – mplungjan
      Nov 19 '18 at 16:09




      Ok, updated.....
      – mplungjan
      Nov 19 '18 at 16:09












      This is really tidy, but I am getting document.getElementsByClassName('my-ratings').forEach is not a function
      – Takuhii
      Nov 19 '18 at 16:21




      This is really tidy, but I am getting document.getElementsByClassName('my-ratings').forEach is not a function
      – Takuhii
      Nov 19 '18 at 16:21












      Please see update. I changed to use querySelectorAll and IE does not like forEach on nodes - I could have created a working example if I'd had the HTML
      – mplungjan
      Nov 19 '18 at 16:23






      Please see update. I changed to use querySelectorAll and IE does not like forEach on nodes - I could have created a working example if I'd had the HTML
      – mplungjan
      Nov 19 '18 at 16:23














      One more thing, getRating is now not defined, do I just create a const and place the document.querySelectorAll in it?
      – Takuhii
      Nov 19 '18 at 16:32




      One more thing, getRating is now not defined, do I just create a const and place the document.querySelectorAll in it?
      – Takuhii
      Nov 19 '18 at 16:32












      Ah no. I assume rate.classList.add
      – mplungjan
      Nov 19 '18 at 16:34




      Ah no. I assume rate.classList.add
      – mplungjan
      Nov 19 '18 at 16:34













      1














      You need to convert the string to Number.



      Change



      getRatingValues += getRating[i].textContent;


      to



      getRatingValues += Number(getRating[i].textContent);


      Also, your getRatingValues should not be initialized to , instead it should be



      let getRatingValues = 0;





      share|improve this answer





















      • For completeness, it's probably worth mentioning you can cast the value to a number in a variety of different ways: += Number(var) or += parseInt(var) or, my favorite, += +var....
        – cale_b
        Nov 19 '18 at 16:07
















      1














      You need to convert the string to Number.



      Change



      getRatingValues += getRating[i].textContent;


      to



      getRatingValues += Number(getRating[i].textContent);


      Also, your getRatingValues should not be initialized to , instead it should be



      let getRatingValues = 0;





      share|improve this answer





















      • For completeness, it's probably worth mentioning you can cast the value to a number in a variety of different ways: += Number(var) or += parseInt(var) or, my favorite, += +var....
        – cale_b
        Nov 19 '18 at 16:07














      1












      1








      1






      You need to convert the string to Number.



      Change



      getRatingValues += getRating[i].textContent;


      to



      getRatingValues += Number(getRating[i].textContent);


      Also, your getRatingValues should not be initialized to , instead it should be



      let getRatingValues = 0;





      share|improve this answer












      You need to convert the string to Number.



      Change



      getRatingValues += getRating[i].textContent;


      to



      getRatingValues += Number(getRating[i].textContent);


      Also, your getRatingValues should not be initialized to , instead it should be



      let getRatingValues = 0;






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 19 '18 at 16:04









      Dinesh Pandiyan

      2,465825




      2,465825












      • For completeness, it's probably worth mentioning you can cast the value to a number in a variety of different ways: += Number(var) or += parseInt(var) or, my favorite, += +var....
        – cale_b
        Nov 19 '18 at 16:07


















      • For completeness, it's probably worth mentioning you can cast the value to a number in a variety of different ways: += Number(var) or += parseInt(var) or, my favorite, += +var....
        – cale_b
        Nov 19 '18 at 16:07
















      For completeness, it's probably worth mentioning you can cast the value to a number in a variety of different ways: += Number(var) or += parseInt(var) or, my favorite, += +var....
      – cale_b
      Nov 19 '18 at 16:07




      For completeness, it's probably worth mentioning you can cast the value to a number in a variety of different ways: += Number(var) or += parseInt(var) or, my favorite, += +var....
      – cale_b
      Nov 19 '18 at 16:07











      0














      Like my comment you can optimize your code very easy:



      that optimized Code:



      const getRating = document.getElementsByClassName('my-ratings');
      for(var i = 0; i < getRating.length; i++) {
      getRatingValues += Number(getRating[i].textContent);
      if (getRatingValues !== undefined) {
      getRating.classList.add('rating-' + i);
      }
      }





      share|improve this answer


























        0














        Like my comment you can optimize your code very easy:



        that optimized Code:



        const getRating = document.getElementsByClassName('my-ratings');
        for(var i = 0; i < getRating.length; i++) {
        getRatingValues += Number(getRating[i].textContent);
        if (getRatingValues !== undefined) {
        getRating.classList.add('rating-' + i);
        }
        }





        share|improve this answer
























          0












          0








          0






          Like my comment you can optimize your code very easy:



          that optimized Code:



          const getRating = document.getElementsByClassName('my-ratings');
          for(var i = 0; i < getRating.length; i++) {
          getRatingValues += Number(getRating[i].textContent);
          if (getRatingValues !== undefined) {
          getRating.classList.add('rating-' + i);
          }
          }





          share|improve this answer












          Like my comment you can optimize your code very easy:



          that optimized Code:



          const getRating = document.getElementsByClassName('my-ratings');
          for(var i = 0; i < getRating.length; i++) {
          getRatingValues += Number(getRating[i].textContent);
          if (getRatingValues !== undefined) {
          getRating.classList.add('rating-' + i);
          }
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 16:07









          episch

          304114




          304114























              0














              Try parseInt



              getRatingValues += parseInt(getRating[i].textContent);


              Reference : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt






              share|improve this answer




























                0














                Try parseInt



                getRatingValues += parseInt(getRating[i].textContent);


                Reference : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt






                share|improve this answer


























                  0












                  0








                  0






                  Try parseInt



                  getRatingValues += parseInt(getRating[i].textContent);


                  Reference : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt






                  share|improve this answer














                  Try parseInt



                  getRatingValues += parseInt(getRating[i].textContent);


                  Reference : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 19 '18 at 16:15









                  mplungjan

                  86.8k20122181




                  86.8k20122181










                  answered Nov 19 '18 at 16:05









                  Anurag Sinha

                  533513




                  533513






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378452%2ftrying-to-convert-a-numeric-value-to-css%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      MongoDB - Not Authorized To Execute Command

                      How to fix TextFormField cause rebuild widget in Flutter

                      Npm cannot find a required file even through it is in the searched directory