开发者

how can i hide a table cell based on a previous cell?

I have table cells that include (data-attribute="description") that I want to hide (or the contents within) only if the previous cell includes (data-v开发者_如何学编程alue="email") or (aria-label="Email")

.crmEntityFormView table.table td

<td data-type="System.String" data-attribute="activitytypecode" data-value="email" data-th="Activity Type" aria-label="Email">Email</td>

<td data-type="System.String" data-attribute="description"> something </td>

Any thoughts on this?


With jQuery you can use prev to get the previous sibling, so select all td elements with data-attribute description and iterate the collection checking each sibling for the required data-value and aria-label:

$(function(){
  $('td[data-attribute="description"]').each(function(){
      const $prev = $(this).prev();
      if($prev.length && 
        ($prev.data('value') === 'email' || 
         $prev.attr("aria-label") === 'Email')){
            $(this).hide();
      }
  });
});
<script
  src="https://code.jquery.com/jquery-3.6.1.js"
  integrity="sha256-3zlB5s2uwoUzrXK3BT7AX3FyvojsraNFxCc2vC/7pNI="
  crossorigin="anonymous"></script>
<table>
<tr>
    <td data-type="System.String" data-attribute="activitytypecode" data-value="email" data-th="Activity Type" aria-label="Email">Email</td>
    <td data-type="System.String" data-attribute="description"> something </td>
</tr>
<tr>
     <td data-type="System.String" data-attribute="activitytypecode" data-value="not-email" data-th="Activity Type" aria-label="Not-Email">Not Email</td>
     <td data-type="System.String" data-attribute="description"> something </td>
</tr>
</table>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜