Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change text of th of table in jquery?

I have table like below

<table>
 <tr> <th>Document</th> <th>...</th></tr>
 <tr><td>...</td>... </tr>
 ...
</table>

Now I want to change the text of th "Document" to "Marketting Document/URL"BY jQuery... Please help me!!!


2 Answers

$("table tr>th:first").html("Marketting Document/URL");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
 <tr><th>Document</th> <th>1</th></tr>
 <tr><td>2</td><td>3</td> </tr>
</table>

Try something like this:

console.log($("table tr>th:first").html("Marketting Document/URL"));
like image 119
Mox Shah Avatar answered Oct 17 '25 00:10

Mox Shah


You can try this : use jQuery selector to get first tr and then fist th inside it. Then use .text() or .html() method to update your desired value.

$(function(){
  $('table tr:first th:first').text('Marketting Document/URL');
 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<table>
  <tr>
    <th>Document</th>
    <th>second header</th>
  </tr>
  <tr>
    <td>first td</td>
    <td>second td</td>
  </tr>
</table>
like image 41
Bhushan Kawadkar Avatar answered Oct 17 '25 00:10

Bhushan Kawadkar