简体   繁体   中英

jquery change td text

<td>09 Mars 2020</td>

I have a div constructed using the above string.

the Jquery variables that I have

date1 = 09 Mars 2020
date2 = 18 Mars 2020

I just wanted to add content from another date with that date to get a result like that

<td>09 Mars 2020 - 18 Mars 2020</td>

the td that I have on the html page has nothing id nothing name nothing to value there is that the date display and I know it on a variable it misses that like looking for it to find td

<tr>
  <td>
    <table class="nobordernopadding" width="100%">
      <tbody>
        <tr>
          <td>Date prévue de livraison</td>
          <td align="right"><a href="/commande/card.php?action=editdate_livraison&amp;id=56"><span class="fa fa-pencil marginleftonly valignmiddle pictoedit" style=" color: #444;" alt="Définir la date d'expédition" title="Définir la date d'expédition"></span></a>
          </td>
        </tr>
      </tbody>
    </table>
  </td>
  <td>09 Mars 2020</td>
</tr>

Given your provided markup, one possible path for selection is:

$('.nobordernopadding')
    .closest('td')
    .next('td')
    // conditionally filter the td on the desired target text
    .filter(':contains("09 Mars 2020")')
    .text('my new value')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM