1

I'm working on a project where I'm parsing a json file to get the contents then do $.post using php to update changes. I'm able to read and write without any issues.

However, after I parse the data from json, I if I make any changes like adding a new class via click it adds the class but doesn't apply the css.

Ex:

    <div id="someID">lorem ipsum</div> <!-- (assuming I am "appending" this div via jquery and if I clicked on this div)

    <!-- it will become -->
    <div id="someID" class="red">lorem ipsum</div> <!-- the text and/or background should be red -->

I think I can apply a style="color: red" instead of applying class but I don't want that.

Any suggestions on how I can make this dynamic/live? Thanks.

4
  • I think the key thing is appending content to the body. Commented Sep 25, 2012 at 15:21
  • What makes you think the class is added if the style doesn't update? Can you create a working demo in jsfiddle.com? Commented Sep 25, 2012 at 15:22
  • Can you add your CSS to the example? Commented Sep 25, 2012 at 15:22
  • I've made a logical error, it's all set now. Thanks. Commented Oct 4, 2012 at 17:58

3 Answers 3

2
$("#someID").addClass("class_name_you_want_to_add");

for further reference you may want to look at http://api.jquery.com/addClass/

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

Comments

1

Class will work fine using .addClass.

Look here: http://jsfiddle.net/TeHtz/

Comments

0
$('#someID').addClass("red")

Try that

Comments

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.