Reputation: 1277
I am trying to replace the text of a list element and maintain the stylying of the original class, however, when I replace it overwrites the CSS. When I try add new styling to it it doesn't seem to work. I may be mis-understanding the html() function - can it have styling applied to it?
$('#listElement>li:eq(1)').html('replacement text').addClass('.progressStep')
$('.progressStep').css({
'width': '140px',
'display': 'block',
'margin': '10px 0 0 -60px',
'color': '#c5c5c5'
})
Upvotes: 0
Views: 46
Reputation: 82241
You have passed .progressStep
as argument to .addClass()
. which is adding class .progressStep
and not progressStep
You do not need to use class selector in .addClass()
method. you should simply pass classname(s) as an argument. In current case, use addClass('progressStep')
instead of addClass('.progressStep')
:
$('#listElement>li:eq(1)').html('replacement text').addClass('progressStep')
Upvotes: 1
Reputation: 24019
Try this:
$('#listElement>li:eq(1)').text('replacement text').addClass('.progressStep')
You only need to use html
if you're actually adding html
Upvotes: 0