Find td with specific text, and operate on the td right after that one?

前端 未结 6 665
逝去的感伤
逝去的感伤 2020-12-19 04:13

I\'m not very familiar with jQuery selectors, so would like some help.

I have a table like this:

6条回答
  •  暖寄归人
    2020-12-19 04:57

    First, you want to use :contains:

    jQuery( "td:contains(text)" );
    

    Then, you can use .next and .append:

    jQuery( "td:contains(text)" ).next().append("Hello");
    

    Here's a working snippet to demonstrate usage:

    jQuery(function($) {
      $("td:contains(Text to Find)").next().append(" Hello");
    });
    table {
      border-collapse: collapse;
    }
    
    td {
      border: 1px solid #ccc;
      padding: 2px 5px;
    }
    
    
    Some Text More Text YMT
    Text to Find Modify: Do nothing here

提交回复
热议问题