Alex
Alex

Reputation: 77

change or add style to variables on tags?

how can change style of variables on tags?

information :

 var $classi = $("#class").val();
 var $id = $("#id").val();
 var $value = $("#value").val();

$("#").append('<input class="default ' + $classi + '" type="text" id="' + $id + '" value="' + $value + '"' ');

i want addstyle to $value

$value.css('text-align','right') ;

is incorrect . because when i tried that . elements were not made . i want to change or add style values . how can i do that?

Upvotes: 2

Views: 200

Answers (1)

matthias_h
matthias_h

Reputation: 11416

You can't add styles to $value because $value is a value - var $value = $("#value").val(); - and not a DOM element. You can add style to the element with the id value like this:

 $("#value").css("text-align", "right");

As your question is how to add styles to variables on tags - if you would declare var $value = $("#value") instead, the expression $value.css("text-align", "right"); would work.

Upvotes: 1

Related Questions