JQuery works in JS fiddle, but not on my website? [duplicate]

半腔热情 提交于 2019-11-28 02:07:14
jfriend00

Your jsFiddle is set for onload in the upper left of the jsFiddle window. If you set it to "No Wrap - in Head" which simulates code in the <head> tag, then your jsFiddle no longer works.

The onload setting means that jsFiddle doesn't run your javascript until the page has been loaded.

In your real page, you are probably running the javascript too soon before the page has been loaded.

You can either fix that by putting your javascript in it's own .ready() function:

$(document).ready(function(){
    $(".image").css("border","3px solid red");
});

Or, you can make sure the javascript isn't loaded/run until right before the </body> tag which is a simple way to make sure the content of your page is loaded before the script runs.

<body>
Your HTML content here

<script>
// your script here that runs after all of the DOM is parsed
$(".image").css("border","3px solid red");
</script>

</body>

See this answer for more details on placing the <script> tag appropriately.

Have you test adding inside $(document).ready(function(){}); ?

<script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
<script>
    $(document).ready(function(){
        $(".image").css("border","3px solid red");
    });
</script>
if u have a internet connection following link useful for you 

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script> 

above link put inside a body or before write a script and please verify jquery js file.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!