1

I have recently asked a question about this. But after starting a new project, I cannot figure out how to display a number of businesses in the system. There are 0 businesses. How do I make the p tag show it up?

<script>var businessesfound = 0; document.getElementById('businessamount').innerHTML = "Business amount:" + businessesfound;</script>

Please help! Thanks for all the support you have given me on other questions :)

  • Oh wait btw for some reason it's not showing up, but after the –  May 18 '17 at 22:07
  • script should go at the end of the body tag – Ahmed Eid May 18 '17 at 22:09
  • presuming the p tag is the element with the 'businessamount' id... Place the script tag after the p tag – joopmicroop May 18 '17 at 22:09
  • Possibly related: [Why does jQuery or a DOM method such as getElementById not find the element?](https://stackoverflow.com/questions/14028959/why-does-jquery-or-a-dom-method-such-as-getelementbyid-not-find-the-element) – Jonathan Lonowski May 18 '17 at 22:16

2 Answers2

0

The script is executed before the Tag is defined, so the JavaScript just can´t find it. Have a look in the F12-Tools / Console!

earloc
  • 1,895
  • 9
  • 19
0

Make sure the script tag is added after the div tag OR run the script after the DOM is ready, like this:

$( document ).ready(function() {
   var businessesfound = 0; 
document.getElementById('businessamount').innerHTML = "Business amount:" + businessesfound;
});

var businessesfound = 0; document.getElementById('businessamount').innerHTML = "Business amount:" + businessesfound;
<p id="businessamount"></p>
Polynomial Proton
  • 4,421
  • 15
  • 37