Delete CSS applied to Brothers object clicked with Javascript

0

How could resetar a CSS applied with Javascript via Click element? I have a table whose tr and td are dynamically created and a table table is created directly in% static%, HTML of course does not have td this CSS is applied when CSS is clicked because I do not want to delete the td of the other CSS siblings of td clicked.

HTML Table Code:

<table id="palavras">
<tbody>
   <tr>
      <td>Cadillac</td>
   </tr>
   <tr>
       <td>Cachorro</td>
   </tr>
   <tr>
      <td>Camaro</td>
   </tr>
 </tbody>
 </table>

Javascript code resposable by adding td (fucnionando) and disallowing siblings of the element clicked:

$('body').on('click', ' #palavras td', function (e){
    $(this).css('background-color', '#333');
    $(this).siblings().css('background-color', '#fff');
});
    
asked by anonymous 26.05.2015 / 14:59

1 answer

2

You can do this as follows.

$('body').on('click', ' #palavras td', function (e){
    $('#palavras td').each(function(){
    $(this).css('background-color', '#fff');
    })

    $(this).css('background-color', '#333');

});
    
26.05.2015 / 15:23