Reputation: 6259
I wrote this jQuery code:
<script>
$(".text").click(function() {
$("#Content").html($(this).next(".text1").html());
});
</script>
But I did something wrong, I get this error:
Uncaught ReferenceError: $ is not defined 15:16618
(anonymous function)
I have really no clue how to solve it! Please inform me if you need my html thanks!
UPDATE:
Somehow my code only works when the class="text"
is wrapped into an p
-tag:
<p class="text">
<a>B35.-Dermatophytose [Tinea]</a><a class="hidden id_code">587</a>
</p>
<div class="text1" style="display: none">
<p class="text">
<a class="num">B35.-</a><a class="bez">Tinea barbae</a>
<a class="hidden id_code">587</a>
<a class="hidden notation"></a>
<a class="hidden schlussel">j</a>
</p>
<p class="text">
........
When it's in the a
-tag it wont work: What's going on?
<a class="text">B35.-Dermatophytose [Tinea]</a>
What do I have to change?
Upvotes: 0
Views: 825
Reputation: 28837
Add this to your page, inside the <head>
tags:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
If the $
is not defined I suspect jQuery's library is not loaded, this file will do that.
Another problem you might have is that the script you posted has to be after the html it refers to. Otherwise the code might give a error because it refers to html that is not there (yet).
You can wrap you code in a DOM ready function like: $(document).ready(function(){ ...your code... });
Or put your script code in the very bottom of the page, just before the </body>
tag (end of the body).
Keep in mind that if you have other .js
files that needs jQuery: that jQuery should be loaded before them.
Upvotes: 2