Função jquery não funciona

.NET

02/08/2013

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

Curtidas 0

Respostas

Joel Rodrigues

Joel Rodrigues

02/08/2013

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

Pjava

02/08/2013

Uncaught ReferenceError: $ is not defined

Esse é o erro que aparece no Console. Parece meio genérico esse erro.
GOSTEI 0
Joel Rodrigues

Joel Rodrigues

02/08/2013

Isso ocorre geralmente quando falta referência à jQuery.
GOSTEI 0
João Marques

João Marques

02/08/2013

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>
GOSTEI 0
Joel Rodrigues

Joel Rodrigues

02/08/2013

E aí, PJava?
GOSTEI 0
Gabriel Simas

Gabriel Simas

02/08/2013

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
GOSTEI 0
POSTAR