views:

92

answers:

2

my textbox has a class='cssText'. I want to change this class to 'blck' at runtime.

How can I access the class attribute of textbox and change its value using jQuery?

Thanks

+2  A: 
$("input#id").removeClass("cssText").addClass("blck");

or

$("input#id").attr("class", "blck");
Seb
A: 

You shoudl select the textbox and then set the new class:

$(selector_for_textbox).removeClass('cssText').addClass('blck');

A possible selector for your textbox could ofcourse be the class, or otherwise an id or something:

$('#textbox'). //etc
$('input.cssText:text'). //etc

Edit from comments
You should use:

$('#txt').removeClass('cssText').addClass('blck');
Pim Jager
can I change any attribute of the textbox like this? - For eg: I have a size attribute and I now want to change its value
You should then use attr(attrName, value); or for css properties: css(property, value); ie: $().css('height', '100px');
Pim Jager