Why is my button not working?

Hi coders,

I’m working on the weather app project and I can’t get my button to switch between Celsius and Fahrenheit. I’m not worried about the symbols at the moment just making the numbers work. Would anyone be able to diagnose the problem for me?

https://codepen.io/BLBaylis/pen/wqMQpQ

You can’t set a click event for an element that doesn’t exist. Right now you’re creating a click event targeting “#fahrenheit” but there are no elements on the page that match that. Instead, you need to bind your click event to the button, and then do logic inside the callback to see if it’s set to fahrenheit or celsius.

One more thing. You should replace your $.html() with $.text().

Also $.prop() with $.attr()

Wow this is excellent. I haven’t come across .data before, so many gaps in my knowledge. o_O Thank you for doing that it is greatly appreciated.

That makes a lot of sense, thanks!