1

I want to append data received from the server to a div on my html page. I can do that with

$('#divImAddingTo').append(infoBeingAppended);

I want to apply a css based style to that data being appended. That I'm not sure how to accomplish.

I tried

$('#divImAddingTo').append(infoBeingAppended).toggleClass = 'className';

This isn't working.

Any help is greatly appreciated, as always.

1
  • hey man please lemme know if my answer worked out for you.. if it did.. marking it as correct won't hurt :p Commented Feb 24, 2013 at 19:08

2 Answers 2

2

try

$('#divImAddingTo').append($('<div class=classname>'));

then

$('#divImAddingTo div').html(contentToAdd);

notice the difference between .append() and .html()

Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried like this?

$('#divImAddingTo').append($(infoBeingAppended).toggleClass('className'));

1 Comment

Ops, you're right. Just got my head ahead the 'apply a css based style' and thought in add :P. I edited my example to toggle the class instead.

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.