I am using this relatively simple code:
var height = help ? 'minus' : 'plus';
var prop = $('#properties');
if(height == 'minus'){
prop.height(prop.height() -= 206);
} else {
prop.height(prop.height() += 206);
}
It fails on both lines that do the adding/subtracting! Any ideas?
The "Invalid left-hand side in assignment" error occurs when we have a syntax error in our JavaScript code. The most common cause is using a single equal sign instead of double or triple equals in a conditional statement. To solve this, make sure to correct any syntax errors in your code.
A single “=” sign instead of “==” or “===” is an Invalid assignment.
The JavaScript exception "invalid assignment to const" occurs when it was attempted to alter a constant value. JavaScript const declarations can't be re-assigned or redeclared.
The -=
operator equals operand = operand - value
which in your case would look like
prop.height() = prop.height() - 206;
which obviously will fail. You just need the minus operator to accomplish that task.
prop.height(prop.height() - 206);
will do it.
you can't -= a method.
either you need to prop.height(prop.height() - 206);
or collect the value first and then -= it like...
var h = prop.height();
h -= 206
prop.height( h);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With