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...
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.
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.
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.
“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).
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.
The first one should work. Are you wrapping it in $(document).ready(function(){}); ?
$(document).ready(function(){
$('#hiddenTr').show();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With