Função jquery não funciona

02/08/2013

0

O que está errado nessa função jquery?
<div id="div1" style="width: 100px; height: 100px; background-color: green; color: #000;"></div>
    <a onclick="$('#div1').animate(
        { 
        height: 150, width:10, marginLeft:100 
        },5000);$('#div1').animate(
        { 
        height: 100, width:200, marginLeft:150 
        },
        1000);$('#div1').animate(
        { 
        height: 20, width:100, marginLeft:200 
        },
        3000);
        " href="javascript:;">Click here to change the box</a> 
Pjava

Pjava

Responder

Posts

02/08/2013

Joel Rodrigues

Dá uma olhada no console do Chrome pra ver se ele aponta algum erro.
Responder

02/08/2013

Pjava

Uncaught ReferenceError: $ is not defined

Esse é o erro que aparece no Console. Parece meio genérico esse erro.
Responder

02/08/2013

Joel Rodrigues

Isso ocorre geralmente quando falta referência à jQuery.
Responder

08/08/2013

João Marques

Uma solução:


<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("#teste").click(function(){

$("div").animate({
marginLeft:'100px',
height:'150px',
width:'10px'
}, 5000);

$("div").animate({
marginLeft:'150px',
height:'100px',
width:'200px'
}, 1000);

$("div").animate({
marginLeft:'200px',
height:'20px',
width:'100px'
}, 3000);

});
});
</script>
</head>

<body>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;">
</div>

<br/>
<br/>
<br/>
<br/>
<br/>
<br/>

<a href="#" id="teste">Clique aqui!</a>

</body>
</html>
Responder

13/08/2013

Joel Rodrigues

E aí, PJava?
Responder

14/08/2013

Gabriel Simas

O que está errado nessa função jquery?
<div id="div1" style="width: 100px; height: 100px; background-color: green; color: #000;"></div>
    <a onclick="$('#div1').animate(
        { 
        height: 150, width:10, marginLeft:100 
        },5000);$('#div1').animate(
        { 
        height: 100, width:200, marginLeft:150 
        },
        1000);$('#div1').animate(
        { 
        height: 20, width:100, marginLeft:200 
        },
        3000);
        " href="javascript:;">Click here to change the box</a> 


PJava,

Você precisa adicionar o jquery em sua página.

<script src="http://code.jquery.com/jquery-1.9.1.js">
</script>


Forte Abraço
Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar