Targeting a div inside a table

I have a table and want to add a star to a cell when tag is selected. At the moment, if the below .starred is set to display block, it will show in the table as wanted. So I just need to add a class to show the star. The problem I’m having is targeting the anchor. What can I use to target the div.starred in td? tried closest() .find() .parent().find

<tr>
  <td><div class="starred"></div></td>
                <td>Device</td>
                <td>Weight</td>
                <td>Height</td>
                <td>.....</td>
                <td>.....</td>
                <td>12/12/16</td>
                <td> <select> 
                        <option selected="true" disabled="disabled">Select</option>        
                        <option value="offer">Make Offer</option>
                        <option value="counter">Counter Offer</option>
                        <option value="tag">Tag Record</option>
                        <option value="erase">Erase Record</option>
                    </select>
               </td>
            </tr>
.starred{
display:none;
width:30px;
height:30px;
background-image:url("../images/star.png");
position:relative;
background-repeat:no-repeat;
background-position: center 0;
background-size: cover;
}

.showStar{
display:block !important;	
}
$('td select').on('change', function(){
   var val = $(this).val();
      if(val === 'tag') {
         $(this).closest('.starred').addClass("showStar"); 
        }
 else if(val === '...') {
  
        }
  });

Since your in a td and your active object is pointing at the select you must go up 2 levels using parent to get to the tr and then find the td div with your class

$(this).parent().parent().find("td .starred").addClass("showStar");
        $('td select').on('change', function(){
		$(this).parent().parent().find("td .starred").removeClass("showStar");
		
		var val = $(this).val();

		if(val == 'tag') {
			$(this).parent().parent().find("td .starred").addClass("showStar");
			//$(this).closest('.starred').addClass("showStar"); 
		}
		
		else if(val == 'offer') {
			$(this).parent().parent().find("td .starred").addClass("showStar");
			//$(this).closest('.starred').addClass("showStar"); 
		}
	});
1 Like

You beaut! Thanks a lot

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.