I'm having an odd issue. I have a simple page that uses jQuery and CSS, and even though I have the code to embed jQuery via Google API, the javascript isn't working on either my local machine or my web server.
It works fine on JS Bin ( http://jsbin.com/oyimes/2/edit ), just not when I put it all together in Dreamweaver. Here's my code:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Untitled</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
...
JavaScript:
// JavaScript Document
$('.subtitles').hide();
$('#title1').click(function(){
$('#title1subtitles').slideToggle(750,function(){
$('#title1subtitles li div').animate({width:'100%'}, 1500);
});
});
$('#title3').click(function(){
$('#title3subtitles').slideToggle(400,function(){
$('#title3subtitles li div').animate({width:'100%'}, 1500);
});
});
$('#title4').click(function(){
$('#title4subtitles').slideToggle(400,function(){
$('#title4subtitles li div').animate({width:'100%'}, 1500);
});
});
You need to wrap your js code in $(document).ready(function()
$(document).ready(function(){
$('.subtitles').hide();
$('#title1').click(function(){
$('#title1subtitles').slideToggle(750,function(){
$('#title1subtitles li div').animate({width:'100%'}, 1500);
});
});
$('#title3').click(function(){
$('#title3subtitles').slideToggle(400,function(){
$('#title3subtitles li div').animate({width:'100%'}, 1500);
});
});
$('#title4').click(function(){
$('#title4subtitles').slideToggle(400,function(){
$('#title4subtitles li div').animate({width:'100%'}, 1500);
});
});
});
The reason it is working in jsbin is, that it adds the $(document).ready(function(){
for you
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.