Rafael
Rafael

Reputation: 634

How to refresh the CSS so the dynamically generated elements can get styled?

I'm generating some elements dynamically with jQuery, but I already have the classes built in a stylesheet. (I'm modifying an app).
How can I make the classes in the dynamically generated elements work?

All I found was ways to insert style, I don't want it, I want the elements to work with my stylesheet, is there a way?

Upvotes: 0

Views: 137

Answers (1)

Piotr Dajlido
Piotr Dajlido

Reputation: 2030

For appending css .class on runtime you can use .addclass() function

$( "#element" ).addClass( "cssClassName" );

See this for more info: http://api.jquery.com/addclass/

For changing css property on runtime use the .css() function from jQuery library:

$( '.className' ).css( "background-color", color );

See this for more info: http://api.jquery.com/css/

Upvotes: 1

Related Questions