Code from freecodecamp not working in codepen. Why?

Hi,
I’m trying to run simple peace of code form camp in codepen and its not working and I have no idea why.

code from > Change Text with Click Events (263)

http://codepen.io/pietruha8/pen/ZBwMBY?editors=1010

1 Like

Do you have a link to your pen?

What url did you provide for the request?

http://codepen.io/pietruha8/pen/ZBwMBY?editors=1010

Hi,

Go to Settings > Javascript > add jQuery.

Instead of having your javascript between <script> tags, you can just past the code in the Javascript panel.

1 Like

uff, thank you. Now I will try to understand why :blush:

Why what? The function you wrote to change the html is a jQuery code (you can see that because of the $ sign). So it requires the jQuery library to work. The same way that your bootstrap classes won’t work if you don’t link your pen to Bootstrap. :relaxed:

ok, thank you. too long brake in course…

1 Like

Ok thanks that is useful. (I wish they’d explained that in the course manual!)

My code seems to be refreshing immediately after I click the button. Currently here in the code. Any idea how to prevent this?

Hmmm! I’m sure loads of folks have encountered this problem:

When I copy and paste HTML and CSS from FreeCodeCamp into CodePen it doesn’t work. Sometimes nothing appears in the preview window, at best, it appears incorrectly and doesn’t function as it does on the FCC challenges.

Here’s a link to one of mine: https://codepen.io/Fishbite/pen/JmLvWe

Could someone please tell me why and how to correct this please?

Thanks in advance :slight_smile:

Remove the tags from the CSS sheet. You only need those in your HTML files, not in the CSS files :slight_smile:

I mean these <style> tags.

That’s simply awesome! Thank you so much @nielsbom

1 Like