I am not entirely sure on what exactly you are asking but I understood it like that:
You want to use the code from the JSFiddle in your own project and it does not work.
If that is the case, I think you forgot to add a reference to JQuery in your code.
Add this to your HTML:
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
And see if that fixes your problem.
However if it does not fix it, please edit your post with the full code.
2
solved Javascript didn’t load in my html