Replace CSS attribute using Jquery/Javascript

I have following code which have a css class called "formErrorContent"

var promptContent = $('<div>').addClass("formErrorContent").
                                  html(promptText).appendTo(prompt);

Before addiing the class as per the above code. I need to replace the width attribute with some other values like this

   $("#formErrorContent").attr("WIDTH","13");

But the above line is not working and not setting the width attibute to 13 in the css class "formErrorContent"

Please help me on this ... Thanks

Answers


Try this:

$('<div/>', {
  'class': "formErrorContent",
   width: '13px',
   text: promptText
}).appendTo(prompt);

http://jsfiddle.net/Urr2c/1/


Use .css() and change the selector to class, because you set it as class:

var promptContent = $('<div>').addClass("formErrorContent").html(promptText).appendTo(prompt);
$(".formErrorContent").css("width","13px");

you are adding a class but are referring to an id. try

$(".formErrorContent").css("width","13");

Need Your Help

1: command not found

bash variables numbers set sh

I'm writing a divides-by-three function in Bash, and it won't let me set a variable to a number.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.