M.z
M.z

Reputation: 45

Getting text from <td> element using jQuery

if (document.getElementById("td1").innerHTML == "word"){
      $("td:first").html("another word");
}

I just want to check if this have this text .

Upvotes: 1

Views: 5147

Answers (2)

gpasci
gpasci

Reputation: 1440

$("#td1:contains('word')").html("another word");

Test

Upvotes: 1

Nicola Peluchetti
Nicola Peluchetti

Reputation: 76910

You mean

if($('#td1').text() === "word"){
   $("td:first").html("another word");
}

this matches <div id=td1>word</div>

Upvotes: 3

Related Questions