Hey guys I know that there exists .slideToggle()
but I want to add more features later.
I don't know what I'm doing wrong, sliding up works but I cannot slide down.
Can I not overwrite my var? Would be very nice when somebody can help me.
$(document).ready(function () {
var resizeValue = true;
$(".resizeSelect").click(function () {
if (resizeValue === true) {
$(".resize").slideUp(
function () {
$('.parent').height($('.child').height('100'));
});
var resizeValue = false;
} else {
$(".resize").slideDown(
function () {
$('.parent').height($('.child').height('100'));
});
var resizeValue = true
};
});
});
Hey guys I know that there exists .slideToggle()
but I want to add more features later.
I don't know what I'm doing wrong, sliding up works but I cannot slide down.
Can I not overwrite my var? Would be very nice when somebody can help me.
$(document).ready(function () {
var resizeValue = true;
$(".resizeSelect").click(function () {
if (resizeValue === true) {
$(".resize").slideUp(
function () {
$('.parent').height($('.child').height('100'));
});
var resizeValue = false;
} else {
$(".resize").slideDown(
function () {
$('.parent').height($('.child').height('100'));
});
var resizeValue = true
};
});
});
Share
edited Feb 7, 2013 at 14:50
Felix Kling
818k181 gold badges1.1k silver badges1.2k bronze badges
asked Feb 7, 2013 at 14:44
oliverwebroliverwebr
6274 silver badges16 bronze badges
1
- 1 have you tried to put in some consol / alert logs, to see where the code hangs ? – Dukeatcoding Commented Feb 7, 2013 at 14:46
2 Answers
Reset to default 8You shouldn't redefine the resizeValue
variable within the click
function. Just remove var
from var resizeValue
(it should only be used at the top of the ready
-function).
Because you are redeclaring your variable resizeValue in your function instead of update it :
$(document).ready(function () {
var resizeValue = true;
$(".resizeSelect").click(function () {
if (resizeValue === true) {
$(".resize").slideUp(
function () {
$('.parent').height($('.child').height('100'));
});
//DO NOT DECLARE NEW VARIABLE WITH VAR
resizeValue = false;
} else {
$(".resize").slideDown(
function () {
$('.parent').height($('.child').height('100'));
});
//DO NOT DECLARE NEW VARIABLE WITH VAR
resizeValue = true
};
});
});