code fails to work outside a jsFiddle

前端 未结 2 1748
予麋鹿
予麋鹿 2020-12-07 06:11

I aim to make a web page with interactive videos, and while searching here I came across a link pointing to a jsFiddle that suits my needs.

As the code worked perfec

2条回答
  •  心在旅途
    2020-12-07 07:03

    Your jQuery code is running BEFORE the DOM is ready so your jQuery code doesn't find any objects in the page so they don't do anything. You should either locate it at the end of the body AFTER the DOM items are loaded or use jQuery(document).ready() to make your code wait until the DOM is ready.

    Your jsFiddle is set to only run your code after the DOM is loaded so that could be why it works in jsFiddle.

    Change your code to this:

    
    

    You probably also want to fix the location of your script tags. They should either be inside the tags or inside the tags. You have them neither (before tags). Most browsers will likely tolerate, but not technically a good idea.

提交回复
热议问题