jQuery div hide/show problem..?
So I have a hidden div that I’m trying to hide and show with a toggle button, but when I press the toggle button nothing happens.
Javascript code:
// run the function below once the DOM(Document Object Model) is ready
$(document).ready(function() {
// trigger the function when clicking on an assigned element
$(“.toggle”).click(function () {
// check the visibility of the next element in the DOM
if ($(‘div.register’).next().is(“:hidden”)) {
$(‘div.register’).next().slideDown(“fast”); // slide it down
} else {
$(‘div.register’).next().slideUp(“fast”); // hide it
}
});
});
Div:
- Category: JQuery Questions
So I have a hidden div that I’m trying to hide and show with a toggle button, but when I press the toggle button nothing happens.
Javascript code:
// run the function below once the DOM(Document Object Model) is ready
$(document).ready(function() {
// trigger the function when clicking on an assigned element
$(“.toggle”).click(function () {
// check the visibility of the next element in the DOM
if ($(‘div.register’).next().is(“:hidden”)) {
$(‘div.register’).next().slideDown(“fast”); // slide it down
} else {
$(‘div.register’).next().slideUp(“fast”); // hide it
}
});
});
Div:
Other Questions
Login
Search
Recent Comments
- dgdg_dasdad on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- Anas Imtiaz on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- David D on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- Wolfman on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- TnT on Having a Jquery PHP problem?


Clugsworth
Posted 9 months ago
I can see three obvious problems.
$(“.toggle”).click(function () {
You added a space between function and the parenthesis. I’m not sure whether this is an actual problem, or it just seems to trouble me when I do it. It should be:
$(“.toggle”).click(function() {
,
$(‘div.register’).next().slideDown(“fast… // slide it down
You didn’t close your quotations nor your parenthesis on the function. It should be:
$(‘div.register’).next().slideDown(“fast…”) // slide it down
and
if ($(‘div.register’).next().is(“:hidden”)) {
$(‘div.register’).next().slideDown(“fast… // slide it down
} else {
$(‘div.register’).next().slideUp(“fast”)… // hide it
}
First, you have .register, which means the class is register. You need #register, because # means ID. Second, you should put a space between div and #register. Third, you need to remove next(), as that won’t make the div itself slide down, but simply the div after it.
All in all, your code will be:
// run the function below once the DOM(Document Object Model) is ready
$(document).ready(function() {
// trigger the function when clicking on an assigned element
$(“.toggle”).click(function() {
// check the visibility of the next element in the DOM
if ($(‘div #register’).is(“:hidden”)) {
$(‘div #register’).slideDown(“fast…”) // slide it down
} else {
$(‘div #register’).slideUp(“fast”)… // hide it
}
});
});
Don’t forget to import jQuery BEFORE your script!