views:

286

answers:

4

Hello,

I have a div that is hidden and being declared this way:

<div id="divLogin" style="visibility:hidden;">

My idea is to use jquery to make it slide in

so I created this code:

$("btEnviarAcesso").click(function ()
{
    $("divLogin").slideToggle("slow");
});

but it is not working... Does someone have any ideia why??

+1  A: 

You need a pound sign (#) to identify things by their id attribute, which uses the id selector. Try this instead:

$("#btEnviarAcesso")...

and:

... { $("#divLogin").slideToggle("slow"); });

Also, jQuery's show/hide functions don't affect the visibility attribute. Instead, use "display: none" for your element's style.

John Feminella
still doesn't work... :(
Killercode
And a link to the docs: http://api.jquery.com/id-selector/. In a nutshell, selectors in jQuery look a lot like css selectors.
istruble
A: 

if you are using ID in your html, use # in the query name:

$("#btEnviarAcesso").click(function () { $("#divLogin").slideToggle("slow"); });
pixeline
A: 

Your selector is no good, btEnviarAcesso is not an element. It probably needs to be #btEnviarAcesso if it is an id or a .btEnviarAcesso if it is a class.

Nate B
+8  A: 

You are using visibility:hidden to hide the div but the jQuery show functions don't adjust visibility. I would suggest doing this:

<div id="divLogin" style="display: none">

And then change your code to this:

$("#btEnviarAcesso").click(function () {
    $("#divLogin").slideToggle("slow");
});

This assumes an element with the ID of btEnviarAcesso that can take the click event.

EDIT: Make sure you put that code inside a document.ready function:

$(document).ready(function(){ // Or $(function(){ ...
    $("#btEnviarAcesso").click(function () {
        $("#divLogin").slideToggle("slow");
    });
});

You can see this solution working in this demo.

Edit 2

Replace this:

<script src="jquery-1.3.2.min.js"/>
<script language="javascript">

With this:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;
<script type="text/javascript">
Doug Neiner
This is probably the issue, not merely just his forgetting to use the id selector. +1!
John Feminella
that was a excelente approach, but still doesn't work :S
Killercode
@Killercode I updated my answer and added a demo. Check the source of the demo here: http://jsbin.com/oloxo/edit to see where your code might differ from mine. Click "Output" to test how my code works. Does that help?
Doug Neiner
I believe that the problem is that I have the div inside a <form id="form1">May this be the cause???
Killercode
It shouldn't be. Can you post the code to the whole page, or is it proprietary? You can use a service like http://pastie.org to paste it.
Doug Neiner
http://pastie.org/780952
Killercode
OK, i'll look at it and post any changes that are needed. One more question, there is no other CSS on that page? I didn't see a `link` element, but I just wanted to be sure. Also, try my edit to verify jQuery is loading properly by using the Google API version.
Doug Neiner