Abbas Rahimi
Abbas Rahimi

Reputation: 232

How i can make a dynamic css class?

i want to design a dynamic modal-dialog for my component. i get width and height from input and set these to my content div. and may be i have several modal-dialog in one page. how can make it with java script and jQuery ?

Upvotes: 0

Views: 139

Answers (2)

Scary Wombat
Scary Wombat

Reputation: 44813

You can try to use

http://api.jquery.com/css/

as in $( "#mydiv" ).css( "color", "green" )

You can use it with any jquery selector/id, not just class.

$( "#mydiv [name='changeme']" ).css( "color", "green" ); 

Upvotes: 2

Sunil Verma
Sunil Verma

Reputation: 2500

Use as follows :

$( "#mydiv" ).css( "width", $("#widthtextbox').val() );

And

$( "#mydiv" ).css( "height", $("#heighttextbox').val() );

Where widthtextbox and heighttextbox and the ids of the textbox from where you are trying to use values, and mydiv is the div to add css to.

hope this helps you.

Upvotes: 1

Related Questions