Weather App script re-running?

Hello campers,

I’ve gotten most of it put together. But for some reason, my app keeps re-running the entire script when I hit the temperature text to change its unit.

Sometimes, it also behaves differently and will show a blank page after clicking on the text.

Please help!

Thank you.

And here is the link! https://codepen.io/shimphillip/pen/paLJQx

There are at least two ways to resolve. Either:

  1. Add a parameter to your anchor tag’s click event and call the preventDefault function on it

OR

  1. Instead of an anchor tag, use a span tag or some other element with an inline-block display.

Why? Because when you put href="" in your anchor tag without preventing the default action (load a page), then it tries to load the same page again. A blank string for href is the same as putting in the same web page name. Using the 2nd solution above, you avoid needing to prevent any default functionality, because span elements do not have any functionality.

1 Like

Wow… thank you so much, it resolved my issue :slight_smile: