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.
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.
Share Improve this question asked Oct 27, 2011 at 1:14 ThomasThomas 5,09921 gold badges71 silver badges101 bronze badges 1- 3 I think you're trying to mix PHP and JS there... – Clive Commented Oct 27, 2011 at 1:16
2 Answers
Reset to default 7Try
var entry = $('textarea').val();
var formated = '<div class="newsfeed_entry"><p>' + entry + '</p></div>';
$('#entry_container').prepend(formated);
.
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).