In PHP you can do:
$myvar = "Hello";
$myvar .= " world!";
echo $myvar;
The output is: Hello world!
How can I do this in Javascript/jQuery..?
var a = 'Hello';
a += ' world';
alert(a);
You'll get a dialog with "Hello world".
Be careful with this, though:
var a = 3;
a += 'foo';
Result: 3foo. But:
var a = 3;
a += 4;
a += 'b';
You'll get an interesting result, and probably not the one you expect.
The PHP concatenation operator is .
The Javascript concatenation operator is +
So you're looking for +=
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