开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜