Home > Net >  Jquery changing color of a child in parent
Jquery changing color of a child in parent

Time:10-08

how can I change the css of a specific child in $(this).

Right now it changes the color of the whole parent so are there any ways to do this?

 $(document).ready(function(){
        $(".info_td").click(function(){
            $(this).css({'width': '500px','background-color': 'grey'})
          })
    })

CodePudding user response:

You can use children() to do it via jQuery

 $(document).ready(function(){
        $(".info_td").click(function(){
            $(this).children("div:eq(1)").css({'width': '500px','background-color': 'grey','margin':'2px 5px'})
          })
    })
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table border="1">
  <tbody>
    <tr>
      <td>First Column</td>
      <td >
        <div>A1</div>
        <div>A2</div>
        <div>A3</div>
      </td>
    </tr>
  </tbody>
<table>

  • Related