Reputation: 634
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
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