简体   繁体   中英

Jquery addClass and removeClass onclick() not working on fontawesome

I am trying to change the fontawesome icon on a button when i click on it. ie the button is in a table

<tr>
<td> <a href="orders/view/5">#OID005</a></td>
<td> hfg</td>
<td> hhkh</td>
<td> 2015-09-26 16:31:49</td>
<td> 400</td>
<td><button id="#OID005" class="btn btn-info" onclick="work('#OID005','#OID005fa');">
<i id="#OID005fa" class="fa fa-files-o"></i> Take Order</button></td>
<tr>

Here is the JS file for that

function work(e,f){
    $(f).removeClass('fa-files-o');
    $(f).addClass('fa-spinner fa-pulse');
    $(e).prop('disabled',true);
    $('#damnit').slideToggle();
}

Why wont it change the icon?

Remove the # in id

<button id="OID005" class="btn btn-info" onclick="work('OID005','OID005fa');">
     <i id="OID005fa" class="fa fa-files-o"></i> Take Order
</button>

and change you work() like this,

function work(e, f) {
            $("#"+f).removeClass('fa-files-o');
            $("#"+f).addClass('fa-spinner fa-pulse');
            $("#"+e).prop('disabled', true);
            $('#damnit').slideToggle();
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM