When I try pause and play in jsFiddle, my code works but it doesn't work in my html page

Moltres

I found a code online to pause and play a timer. When I used it in jsFiddle, it worked but when I copied the same code into my html page, it didn't work? Can anyone explain why did this happen?
The code in my HTML :

<body onload="start();">
<script>
function start() {
var output = $('h1');
var isPaused = false;
var time = 30;
var t = window.setInterval(function() {
    if(!isPaused) {
        time--;
        output.text("0:" +time);
    }
}, 1000);
}
//with jquery
$('.pause').on('click', function(e) {
    e.preventDefault();
    isPaused = true;
});

$('.play').on('click', function(e) {
    e.preventDefault();
    isPaused = false;
});

</script>
<a href="#" class="play">Play</a>
<a href="#" class="pause">Pause</a>
<h1>0</h1>
</body>
Will Brickner

jsFiddle inserts the <script src="jquery.js"></script> tag automatically.

Here, you must do it yourself.

<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>

This is optional:

Pro Tip: Use a CDN (Content Delivery Network). They have thoroughly optimized delivery, and will often:

I) Send the content from the server physically closest to the end user. This leads to faster load speeds.

II) Caching in the browser. This means that if the site www.example.com already uses the script you want, it never gets loaded again (until the cache is cleared). The old copy is used, and this means no loading time for the script.

In conclusion: Use a CDN! They're often free! Why not?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

In jsfiddle, it works in pure javascript, But - when I include this in my code, it doesn't work without jquery included

Why my application works well but when I try to modularize it, it doesn't work properly?

My discord music bot will play music, but when I try to stop it it doesn't work

My app works fine when I run it from android studio, but doesn't work from google play

html2canvas works on jsfiddle but doesn't work on my site

i try to create a navbar but my javascript code doesn't work

My code won't work in Chrome but works fine in JSFiddle

My JS code works correcty at the tutorial page... on my own doesn't work

When I try to play my Music Discord Bot it doesn't play music

My code doesn’t work when I put in in a function in python

When I include scanf() in my C code it doesn't work

my Array from API response is logged perfectly but it doesn't work when i try to display a title of one object from HTML

I try to display FCM notification in background on my iPhone but it doesn't work when I send this notification with Swift

In my Express Routes When I use '/' end point in my router, it works, however when I change the endpoint to '/login' it doesn't work

I try to write my own makefile but it doesn't work

A function works when I test it with Postman, but doesn't work from my client

HTML 5 Canvas not working in my project, but same code works in JSFiddle?

Why doesn't my SVG display when I try to use the XSLT output method "html"?

View Doesn't Open When I Try To Run My Program?

My code for my messagebox won't work on my window. Everything else works but when I run it my "About" messagebox won't show up

Why my checkboxes doesn't work when I try to launch my userform with a button on the sheet and work when I launch the userform from the main menu?

my code doesn't work anymore but i haven't changed it

i tried to upate my ejs page with fetch but it doesn't work

Why does my Bootstrap Modal window doesn't work on php? When I try to open the modal window it won't display

Mongoose: Incrementing my documents version number doesn't work, and I'm getting a Version Error when I try to save

Homework problem on Java: I'm trying to run my program, it shows no error however when I try to run it it doesn't work?

Python code that works fine on my PC doesn't work on my Raspberry Pi

why my code doesn't work when I am trying to concatenate a function's return value with a string?

Why my code doesn't work when i change line of pointer=&number;?