[英]How do I hide text that is not wrapped in <p> or <span>?
I have html where I only want to hide the text portion, but what complicates it is that it is not wrapped in anything. 我有html我只想隐藏文本部分,但让它变得复杂的是它没有包装在任何东西中。 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:</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? 如何在不更改html的情况下隐藏上面的“给予舒适和持久...”部分? I was hoping to do it via CSS and maybe Javascript if necessary. 我希望通过CSS做到这一点,如果有必要,可能是Javascript。 CSS only would be perfect though. 但CSS只是完美的。 Can anyone help? 有人可以帮忙吗?
Look ma', no hands scripts! 看马',没有手脚本 !
.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;
}
CSS defines the appearance of the contents of a tag. CSS定义标记内容的外观。 No tag, no styling. 没有标签,没有造型。
You need to modify the HTML. 您需要修改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): 使用javascript(和我的jQuery):
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 如果您有多个类别的content
那么您需要重写一下以处理集合
There is no easy way for that. 没有简单的方法。 You'll have to write an html stripper on JavaScript or simply modify your html by hands. 你必须在JavaScript上编写一个html脱衣舞,或者只是手工修改你的html。
CSS: CSS:
#content {
visibility: hidden;
}
JavaScript: JavaScript的:
document.getElementsByTagName("div")[0].style.visibility = "hidden";
or:
document.getElementsByClassName("content")[0].style.visibility = "hidden";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.