jQuery - Error in event handler for 'undefined': TypeError: Cannot call method 'replace' of undefined
I have my own templates with this code in head:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/j开发者_如何学Pythonquery-ui.min.js"></script>
<script type="text/javascript" src="{{MEDIA_URL}}emotions.js"></script>
But in Chrome code spectrator i always have:
Error in event handler for 'undefined': TypeError: Cannot call method 'replace' of undefined
emotions.js:
$(function(){
$('.emotion').click(function(){
var id = $(this).parent().attr('id')
$.post("something/vote/", { emotion: "emotion", id: "id" } )
$('.vote_value').text('You give your vote')});
});
Any sugegestions of what could be wrong?
I almost guarantee that if you log $('.vote_value')
, you'll get undefined. Make sure you have an element with that class present in the dom.
You can also get this error if you ask for the html()
of a <title>
element. For example:
var title = $('title');
var t = title.html();
//-> Error in event handler for 'undefined': TypeError: Cannot call method 'replace' of undefined
var t = title[0].childNodes[0].nodeValue;
//-> "Welcome to My Page!"
I've that error too. I've just turned off an "adBlock" extension. Than I restarted my server and the error disappered.
精彩评论