0

i want to add an attribute to a table header without id or class. all it has is field. my code here does not work. i appreciate any help

$(th[field = "item_group_ID"]).attr('hidden', 'true');

or is there any other way i can do this? heres the table

<table id="dg" title="jaiko pogi " class="easyui-datagrid" style="width:980px;height:370px;"
        url="show_biochem.php"
        toolbar="#toolbar" pagination="true"
        rownumbers="false" fitColumns="true" singleSelect="true" height="auto";>
    <thead>
        <tr>
        <th field="item_group_ID" width="8">ID</th>
        </tr>
    </thead>
</table>

solved it. i read the documentation and turns out there is a function for this. anyway thanks for the help

$('#dg').datagrid('hideColumn','item_group_ID');
raymond
  • 17
  • 1
  • 4

3 Answers3

0

Your selector is incorrect. It should be a string:

$('th[field="item_group_ID"]').attr('hidden', 'true');

Also, are you trying to hide the element? If so, adding an attribute called "hidden" won't do it.. try this instead:

$('th[field="item_group_ID"]').hide();
Jason P
  • 26,984
  • 3
  • 31
  • 45
0

You are missing the quotes:

$("th[field='item_group_ID']").attr('hidden', 'true');

If you are trying to hide the selected element use .hide() function, instead.

Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
0

If you want to use an attribute that is not part of the official HTML syntax (i.e. field), you can use attributes named data-* (i.e. data-field). So:

<th data-field="item_group_ID" width="8">ID</th>

From: https://stackoverflow.com/a/1735268/1165203

Community
  • 1
  • 1
Gábor Imre
  • 5,899
  • 2
  • 35
  • 48