Javascript button pressed fade parent class out only one time works -


hello did when click on 'decline' button fade out 'td' , works works first one, mean if there more <td> contains more 'decline' buttons won't work works on first button

code: javascript

$(function () {     $("#declinebutton").click(function () {         $(this).closest('td').fadeout();     }); }); 

html:

<tr>     <td>         username     </td>     <td>         <button type="button" class="btn btn-danger" name="declinebutton" id="declinebutton">             <span class="glyphicon glyphicon-minus" aria-hidden="true"></span> decline request         </button>         </span>     </td> </tr> 

you have just change declinebutton , id class attribute , change reference in js code, here example :

$(function () {     $(".declinebutton").click(function () {         $(this).closest('td').fadeout();     }); });    <tr>     <td>         username     </td>     <td>         <button type="button" class="btn btn-danger declinebutton" name="declinebutton">             <span class="glyphicon glyphicon-minus" aria-hidden="true"></span> decline request         </button>         </span>     </td> </tr> 

note: ids should unique, meaning 1 id identify 1 , 1 element whereas class can identify more 1 element.

so if want target list of elements give them same class name , ready go, hope helps.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -