ialphan
ialphan

Reputation: 1261

Add class and change css dynamically (jquery)

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.

Upvotes: 1

Views: 3179

Answers (3)

m1k3y3
m1k3y3

Reputation: 2798

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

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

Upvotes: 2

Logan Serman
Logan Serman

Reputation: 29880

Class will work fine using .addClass.

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

Upvotes: 1

Infinity
Infinity

Reputation: 3875

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

Try that

Upvotes: 0

Related Questions