I have html where I only want to hide the text portion, but what complicates it is that it is not wrapped in anything. Below is an example:
<div class="content">
Give comfortable and durable place to work with a desk.
Lock the center drawer and all of the drawers lock,
keeping your files and supplies secure.
<table cellpadding="4" cellspacing="0">
<tbody>
<tr>
<th align="right">Available Options:</th>
<td>Desktop Color: Fusion Maple, Gray Nebula...</td>
</tr>
<tr>
<th align="right">Book Box Construction:<开发者_StackOverflow中文版;/th>
<td>Not applicable</td>
</tr>
</tbody>
</table>
</div>
How can I hide the "Give comfortable and durable..." portion above without changing the html at all? I was hoping to do it via CSS and maybe Javascript if necessary. CSS only would be perfect though. Can anyone help?
Look ma', no hands scripts!
CSS only solution
.content
{
text-indent: -1000em;
}
.content *
{
text-indent: 0;
}
/* This one's pure cherry on top ;) */
/* Remove excess vertical space */
.content *:first-child
{
margin-top: -1em;
}
JSFiddle demo.
CSS defines the appearance of the contents of a tag. No tag, no styling.
You need to modify the HTML. Sorry.
This removes the text node, which is a container for the text:
var div = document.getElementsByTagName('div')[0];
div.removeChild(div.firstChild);
Using javascript (and jQuery in my case):
var table = $('.content table'); //copy the table
$('.content').html(table); //replace the html of div.content with table
If you have multiple classes of content
then you'll need to rewrite this a bit to work over a collection
There is no easy way for that. You'll have to write an html stripper on JavaScript or simply modify your html by hands.
CSS:
#content {
visibility: hidden;
}
JavaScript:
document.getElementsByTagName("div")[0].style.visibility = "hidden";
or:
document.getElementsByClassName("content")[0].style.visibility = "hidden";
精彩评论