32
rated 0 times
[
37]
[
5]
/ answers: 1 / hits: 16864
/ 12 Years ago, sun, april 1, 2012, 12:00:00
How do I use javascript/jquery to change the text on a button in Twitter Bootstrap without destroying the icon?
So, this is my static markup:
<a class=btn id=myButton onclick=doSomething()><i class=icon-ok></i> Do it...</a>
I am able to change the icon, like this:
$('#myButton i:first-child').attr('class','icon icon-remove');
Which is fine, but for the love of all that is good I cannot find a way to set the button text without then wiping out the icon. Eg. if I do this:
$('#myButton').text('Some Remove Text');
I lose the icon element, so how can I access just the text and edit that, whilst preserving any child elements?
More From » jquery