1

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.

1
  • 3
    I think you're trying to mix PHP and JS there... Commented Oct 27, 2011 at 1:16

2 Answers 2

7

Try

var entry = $('textarea').val();    
var formated = '<div class="newsfeed_entry"><p>' + entry + '</p></div>';

    $('#entry_container').prepend(formated);
Sign up to request clarification or add additional context in comments.

Comments

2

. 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).

1 Comment

Ahhh I see... sorry, Im not usually the one who does the javascript stuff, thanks for the explanation!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.