My script works in jsfiddle but not site. Cannot call method hover of null?

一曲冷凌霜 提交于 2019-12-13 22:51:34

问题


I'm getting an error that says "Uncaught typeError: cannot call method 'hover' of null" after $('#nav li a').hover(function(){ in my javascript.

site code: http://pastebin.com/GjZBEu3s jsfiddle: http://jsfiddle.net/jenga/5rfCC/2/


回答1:


You scripting should be in the body of the document, right before the closing </body> tag. If it's loaded in the <head>, the elements it addresses in the document may not be loaded yet. See this jsfiddle (notice 'no wrap (body)' in the 'Choose framework' dialog).

By the way, a similar effect could be achieved using css only. Use this jsfiddle in a Chrome/webkit browser.



来源:https://stackoverflow.com/questions/12293505/my-script-works-in-jsfiddle-but-not-site-cannot-call-method-hover-of-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!