Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change table row display property

I have an html page with a table that contains a hidden row:

<table>
  <tr id="hiddenTr" style="display:none">
    ...
  </tr>
</table>

I need to make it visible at client side using jquery. I tried this

$('#hiddenTr').show();

and this

$('#hiddenTr').css('display', 'table-row');

Both implementations don't work for me. Furthemore the second one is not crossbrowser.

UPD. Sorry, guys. That was my fault: I mistyped tr element id. That's strange $('hiddenTr') didn't return null...

like image 276
SiberianGuy Avatar asked Mar 30 '10 21:03

SiberianGuy


People also ask

How do I change my display property?

Answer: Use the jQuery css() Method You can use the jQuery css() method to change the CSS display property value to none or block or any other value. The css() method apply style rules directly to the elements i.e. inline.

What are the different display properties?

The display property specifies the display behavior (the type of rendering box) of an element. In HTML, the default display property value is taken from the HTML specifications or from the browser/user default style sheet. The default value in XML is inline, including SVG elements.

What is display table property in CSS?

Setting display to table makes the element behave like a table. So you can make a replica of an HTML table without using the table element and corresponding elements such as tr and td . For example, in HTML, you can make a table with the <table> element and also a <div> , or any container of your choice.

What is display inline property means?

“display: inline-block” Property: This property is used to display an element as an inline-level block container. The element itself is formatted as an inline element, but it can apply height and width values. It is placed as an inline element (on the same line as adjacent content).


2 Answers

I always set the style.display property to "" (empty string) to show a hidden table row:

var row = document.getElementById('row_id');
row.style.display = "";   // shows the row

To hide it again:

row.style.display = "none";   // hides the row

in jQuery , this would be:

$("#row_id").css("display", ""); // show the row

or

$("#row_id").css("display", "none");  // hides the row

IE doesn't seem to like the 'table-row' value for display. And 'block' is not correct, and it seems to screw up the display in other browsers sometimes.

like image 183
Ray Avatar answered Sep 26 '22 21:09

Ray


The first one should work. Are you wrapping it in $(document).ready(function(){}); ?

$(document).ready(function(){
    $('#hiddenTr').show();
});
like image 21
Bradley Mountford Avatar answered Sep 23 '22 21:09

Bradley Mountford