Reputation: 5089
Im trying (unsuccessfully) to prepend the following content to a div:
var entry = $('textarea').val();
var formated = '<div class="newsfeed_entry"><p>' . entry . '</p></div>';
$('#entry_container').prepend(formated);
I think the reason it isn't work is related to the way I am mixing variables and text. I looked at the documentation but I can't figure out what the issue is.
Upvotes: 1
Views: 7081
Reputation: 490183
.
is for object property lookup in JavaScript. You may have been in the PHP world for too long.
You can concatenate strings in JavaScript with the String
object's concat()
method or with +
(it is overloaded to do arithmetic addition and string concatenation).
Upvotes: 2
Reputation: 6955
Try
var entry = $('textarea').val();
var formated = '<div class="newsfeed_entry"><p>' + entry + '</p></div>';
$('#entry_container').prepend(formated);
Upvotes: 7