1

I want to hide the value of column in table, the data of table is bind from database

This is my html code

<table id="datatable-responsive" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">                                                                          
<thead>
   <tr>
      <th id="th_id_event">Id Event Category</th>
      <th>Event Category</th>
      <th>Description</th>
   </tr>
</thead>
<tbody>
  <% objLOV.forEach(function (lov) { %>
  <tr onclick="callme(this)">
    <td id="td_id_event">
       <%= lov.id %>
    </td>
    <td>
       <%= lov.event_category %>
    </td>
    <td>
       <%= lov.description %>
    </td>
 </tr>
<% }) %>
</tbody>
</table>

<% objLOV.forEach(function (lov) { %> is to get data from database

I have tried like this, but the only first column first row get hide, I want hide all the value of the column id

window.onload = function () {
        document.getElementById("td_id_event").style.display = "none";
        document.getElementById("th_id_event").style.display = "none";
   };

my table

my table after i tried to disable

can anyone help me? thank you..

2
  • 1
    Don' use Id, use class instead of Id Commented Mar 13, 2018 at 3:48
  • thank you.. @NitinDhomse Commented Mar 13, 2018 at 3:58

1 Answer 1

3

You can only validly have one element with a given id so attempting to reference multiple elements with the same id is unlikely to work. You could use a class for the element instead i.e. replace

<td id="td_id_event"

with

<td class="id_event"

and then use

window.onload = function () {
    var ids = document.getElementsByClassName("id_event");
    for (var i = 0; i < ids.length; i++) {
        ids[i].style.display = "none";
}
Sign up to request clarification or add additional context in comments.

2 Comments

may i ask? i use datatable, and when i click next to show the next data, why the value of the column are not hidden @Nick
Perhaps because you are not reloading the window? The function only runs when the window is loaded. You should probably ask a new question and supply as much information as you can (e.g. what does clicking next do exactly)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.