I’m trying it with this one, but sometimes the .click() just automaticly does the command not waiting for actual click.
var x = 0;
if ($('#business').click() && (x = 0)) {
$('#business').css('height', '500px');
x = 1;
} else if ($('#business').click() && (x = 1)) {
$('#business').css('height', '100px');
x = 0;
}
I can resize it with the below code, but unfortunately dont know how to change back on click again.
$('#business').click(function(){
$('#business').css('height', '500px')
})
2
Answers
If you use
$('#business').click()
, it will actually simulate a click on your event.If you want to have an action done on the click on your
div
, you should use your 2nd form:In order to be able to change the height from one value to the other, you have two way for doing that:
data-*
property on yourdiv
element, test its value and set your height accordingly (and change the value of this property)For instance, you could do something like this:
Just toggle a class so there is no worrying about what state it should be in. Avoid setting css style properties directly in JavaScript.