Calculator App - Trigger click event for a span tag. Need Help

Calculator App - Trigger click event for a span tag. Need Help


Hi Everyone,

I need help triggering the on click event on a span tag. After researching a bit on stack overflow, I found out that I am supposed to use the $(document).on(“click”,“id”,"function(){}); and not $( “#target” ).click(function() {}.
But I am still not able to traverse through the span tag which has id=“7”. The idea is to display the number 7 when clicked on span tag 7. Can anybody help me achieve this?

Thank you!


You have 3 problems:

  1. You were trying to use Jquery without adding JQuery to your JS section. You had added the Bootstrap 4 link, but not the following:
  1. In JQuery, to reference an element with a specific id, you use something like below (which you did not do):
  1. Even if you correctly referenced the element (#2 above), your span which contained the number 7 in the html looks like:
<span id="#7">7</span>

If using JQuery, your id name in the html element tag can not have the “#” in front of it.

  1. One last problem you would notice if you view the console (Ctrl + Shft + I in chrome), is that since you are using Bootstrap 4, you need to link to tether.js after the link to Jquery but before the link to Bootstrap 4 in the JS external links section.


Thank you rmdawswon71! Adding JQuery library did the trick. Sometimes, we tend to overlook the important little things. It is working perfectly now.