Forum Moderators: open
var a = 2;
var b = a;
var c &= a;a += 2;
alert(b) // result: 2;
alert(c) // result: 4;
ideally what I want to do is something like this:
var b = 200;
var a = document.getElementById('someelement');
var c = document.getElementById('anotherelement');
var d = document.getElementById('a3rd');a.style.height &= b/4;
c.style.width &= b*2;
d.style.height &= (0.5*b)/a;
..
..
b=100 // the 3 elements automatically resizing without having to
// assign the values to each element all over again
Good ideas?
There is a bitwise operator & and a related assignment operator &= in Javascript.
It performs in the same way as in php.
Here's O'Reilly on the Javascript:
Bitwise And (&)
The & operator performs a boolean AND operation on each of its integer arguments. A bit is set in the result only if the corresponding bit is set in both operands.
...and the php manual [php.net]:
Table 11-3. Bitwise Operators
Example: $a & $b
Name: And
Result: Bits that are set in both $a and $b are set
I have no experience using bitwise operators so that's as far as I can help. Perhaps you could explain how you're using them. I've done some image size manipulation for formatting a table of thumbnails according to screen resolution using Javascript but my calculation method used only logical operators.
You can only set a variable using = or +=. Once you set the value, it stays exactly the same until you set it to something else.
HTH