is there a way to change two texts in list element with javascript

my problem is that when i use two .textContent method on the same list element to change text it doesn’t work , but when i comment the if else block everything go well. all what i want is to display both of them after changing textcontent ,but when i do that the spans content disappear which has temperatures.

// those are just selectors i think theres nothing wrong with them
const span1 = document.querySelector('#span1');
const span2 = document.querySelector('#span2');
const span3 = document.querySelector('#span3');
const span4 = document.querySelector('#span4');
const span5 = document.querySelector('#span5');

const list1 = document.querySelector('#l1')
const list2 = document.querySelector('#l2');
const list3 = document.querySelector('#l3');
const list4 = document.querySelector('#l4');
const list5 = document.querySelector('#l5');
// those are just selectors i think theres nothing wrong with them


if ((currentHour + 3) >= 10) {
  list1.textContent = "Now";
  list2.textContent = `${currentHour + 3}:00`;
  list3.textContent = (currentHour + 6) + ':00';
  list4.textContent = (currentHour + 9) + ':00';
  list5.textContent = (currentHour + 12) + ':00';
} else {
  list1.textContent = "Now";
  list2.textContent = '0' + (currentHour + 3) + ':00';
  list3.textContent = '0' + (currentHour + 6) + ':00';
  list4.textContent = '0' + (currentHour + 9) + ':00';
  list5.textContent = '0' + (currentHour + 12) + ':00';
}

span1.textContent = data.currentTemp + '°C';
span2.textContent = data.temp3 + '°C';
span3.textContent = data.temp6 + '°C';
span4.textContent = data.temp9 + '°C';
span5.textContent = data.temp12 + '°C';
<ul>
  <li id="l1">Now<span id="span1"> </span></li>
  <li id="l2">09:00<span id="span2"> </span></li>
  <li id="l3">12:00<span id="span3"> </span></li>
  <li id="l4">15:00<span id="span4"> </span></li>
  <li id="l5">18:00 <span id="span5"> </span></li>
</ul>

166 thoughts on “is there a way to change two texts in list element with javascript”

  1. i need loan urgently in dubai, i need a loan on my prepaid debit card. i need loan urgently in dubai need loan now i need a loan today i need education loan, cash advance loans direct lender, cash advance online, cash advance online, cash advance loans brisbane. Money describes business, provides business loans.

    Reply

Leave a Comment