1

I'm developing budget diary web app and have problems with frontend, I have problems with updating budget . Here is my code for Income:

script.js

var sum =0;
 $('#li-income-val').each(function() {
  sum += Number($(this).text());

});
$("#budget-income").text(sum)

html code

  <li id="li-icnome">
    <p class="dashboard__income__text">
        {{incom.title}}
    </p>
    <p id="li-income-val">{{incom.value}}</p>
    </p>
</li>

Is there any solutions ?

1
  • 1
    You've not really described the problem here, only told us that you have one. What is it? That being said, it looks like you're repeating the same id on all the li and p elements which is invalid; they have to be unique in the DOM. Change it to a class. Commented Feb 22, 2020 at 20:56

1 Answer 1

1

First of all Use class instead of id (id should be one)

HTML

<li class="li-icnome">
  <p class="dashboard__income__text">
    {{incom.title}}
  </p>
  <p class="li-income-val">{{incom.value}}</p>
</li>

JS

  var sum =0;
  $('.li-income-val').each(function() {
   sum = sum + parseInt($(this).text());
  });
  $("#budget-income").text(sum);
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.