Reputation: 129
<div class='progress-20'>
I want to alter the progress-20 with other value, I've get the value by custom expression.
Upvotes: 1
Views: 1908
Reputation: 148110
You can use attr() to set the class attribute of the element. You need to select the div for that you can use class selector.
$('.progress-20').attr('class','newclass');
Edit based on comments.
You can use starts with attribute selector if 20 could change
$('[class^=progress-]').attr('class','newclass');
Upvotes: 1
Reputation: 34107
Try this Demo: http://jsfiddle.net/Ja2SU/
OR this demo http://jsfiddle.net/bFLju/
*API:
attr
http://api.jquery.com/attr/removeAttr
http://api.jquery.com/removeAttr/addClass
http://api.jquery.com/addClass/you could use attr
or removeClass
and then addClass
Gave you few choices hope anyone will fit you need :)
Code
$(function () {
alert(' before altering => ' + $('div').attr('class'));
$('div').attr('class', 'foobar');
alert(' after altering => ' + $('div').attr('class'));
});
or
$(function () {
$('div').removeAttr('class').addClass('foobar');
});
Upvotes: 0
Reputation: 40639
Try toggleClass() like,
$('div').toggleClass('progress-20 newclass');
Upvotes: 1