隐藏特定类的所有元素 [英] Hide all elements of a specific class

查看:48
本文介绍了隐藏特定类的所有元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个任务看起来很简单,但我不确定这是否可行,或者甚至是正确看待它的方式......


我有< td class =" X" elements其中X和X。是类名的占位符

A,B等。现在我想显示/隐藏某个

类的所有< tdelements,说A。静态CSS等价物将是


< style type =" text / css">

.A {visibility:visible; }

.B {visibility:hidden; }

...

< / style>


但是可以动态更改所有<的可见性属性br />
<某个类别的tA以简单的方式使用javascript?


我的意思是,像伪代码一样简单的语法


文档。< whatever(" A" ;)> .visibility = hidden;


或者我是否必须迭代DOM树并将每个元素与

类名进行比较?


非常感谢任何提示。

-

Janis

解决方案

* Janis Papanagnou在comp.lang.javascript中写道


>任务似乎很简单,但我不是确定这是否可行,或者甚至是正确的方式来看待它...

我有< td class =" X" elements whereX是类名的占位符
A,B等。现在我想显示/隐藏某个类的所有< tdelements,比如说A。静态CSS等价物将是


< style type =" text / css">

.A {visibility:visible; }

.B {visibility:hidden; }

...

< / style>

但是可以动态更改所有
<的可见性属性;某类A的元素。以简单的方式使用JavaScript?



您可以使用

添加/删除/启用/禁用/更改特殊的< styleelement所需的规则;如果你有很多匹配的元素,那么最多可能是
可能是最快的方法。

-

Bj?rn H?hrmann ·mailto:bj **** @ hoehrmann.de· http://bjoern.hoehrmann.de

Weinh。海峡。 22·Telefon:+49(0)621/4309674· http://www.bjoernsworld.de

68309曼海姆·PGP Pub。 KeyID:0xA4357E78· http://www.websitedev.de/


Bjoern Hoehrmann写道:


* Janis Papanagnou在comp.lang.javascript中写道


>>任务看似简单,但我不确定这是否可行,甚至是正确看待它的方法......
我有< td class =" X" elements,其中X是是类名的占位符
A,B等。现在我想显示/隐藏某个类的所有< tdelements,比如说A。静态CSS等价物将是

< style type =" text / css">
.A {visibility:visible; }
.B {visibility:hidden; }
...
< / style>

但是可以动态地更改某个类的所有
< tdelements的可见性属性。 A"以简单的方式使用JavaScript?




您可以添加/删除/启用/禁用/更改特殊的<样式元素和

所需的规则;如果你有很多匹配的元素,那么'bb'可能是最快的方法。



感谢您的快速回复。作为一个关于这个主题的(相当)新手,我似乎仍然缺少一些可能对你来说很明显的基本原因。

我读到了你改变的建议这样的风格,例如,


文件。< whatever> .style.visibility = hidden;

???????? br />

但是我如何改变特定班级_all元素的风格?

换句话说;我不需要一些功能,比如


get_elements_of_class(" A")


来改变风格?


或者你的意思是不同的东西;你能详细说明吗?

-

Janis


* Janis Papanagnou在comp.lang中写道。 javascript


>您可以添加/删除/启用/禁用/更改特殊<具有所需规则的样式元素;如果你有很多匹配的元素,那么最有可能是最快的方法。


感谢您的快速回复。作为这个主题的(相当)新手,我似乎仍然缺少一些可能对你很明显的基本知识。



我说,除了其他建议,你可以添加和删除一个构造

就像


< style type =" text / css">

.A {visibility:visible; }

.B {visibility:hidden; }

...

< / style>

使用createElement和appendChild等方法对文档进行


-

Bj?rn H?hrmann·mailto:bj **** @ hoehrmann.de· http://bjoern.hoehrmann.de

Weinh。海峡。 22·Telefon:+49(0)621/4309674· http://www.bjoernsworld.de

68309曼海姆·PGP Pub。 KeyID:0xA4357E78· http://www.websitedev.de/


The task seems simple but I am not sure whether this is possible or even
the right way to look at it...

I have <td class="X"elements where "X" is a placeholder for class names
"A", "B", etc. Now I want to display/hide all <tdelements of a certain
class, say "A". The static CSS equivalent would be

<style type="text/css">
.A { visibility:visible; }
.B { visibility:hidden; }
...
</style>

but is it possible to dynamically change the visibility attribute for all
<tdelements of a certain class "A" using javascript in a simple way?

I mean, something syntactic simple like the pseudo code

document.<whatever("A")>.visibility = hidden;

Or do I have to iterate over the DOM tree and compare each element against
the class name?

Any hints very much appreciated.
--
Janis

解决方案

* Janis Papanagnou wrote in comp.lang.javascript:

>The task seems simple but I am not sure whether this is possible or even
the right way to look at it...

I have <td class="X"elements where "X" is a placeholder for class names
"A", "B", etc. Now I want to display/hide all <tdelements of a certain
class, say "A". The static CSS equivalent would be

<style type="text/css">
.A { visibility:visible; }
.B { visibility:hidden; }
...
</style>

but is it possible to dynamically change the visibility attribute for all
<tdelements of a certain class "A" using javascript in a simple way?

You can add/remove/enable/disable/change a special <styleelement with
the desired rules; if you have very many matching elements that''ll most
likely be the fastest approach.
--
Bj?rn H?hrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/


Bjoern Hoehrmann wrote:

* Janis Papanagnou wrote in comp.lang.javascript:

>>The task seems simple but I am not sure whether this is possible or even
the right way to look at it...

I have <td class="X"elements where "X" is a placeholder for class names
"A", "B", etc. Now I want to display/hide all <tdelements of a certain
class, say "A". The static CSS equivalent would be

<style type="text/css">
.A { visibility:visible; }
.B { visibility:hidden; }
...
</style>

but is it possible to dynamically change the visibility attribute for all
<tdelements of a certain class "A" using javascript in a simple way?



You can add/remove/enable/disable/change a special <styleelement with
the desired rules; if you have very many matching elements that''ll most
likely be the fastest approach.

Thanks for your quick reply. As a (quite) newbie on the topic I seem to
be still missing something fundamental that is likely apparent to you.

I read your suggestion to change the style as something like, e.g.,

document.<whatever>.style.visibility = hidden;
????????

But how would I change the style of _all elements of a specific class_?
In other words; wouldn''t I need some function like

get_elements_of_class("A")

to make the style change?

Or do you mean something different; can you please elaborate a bit?
--
Janis


* Janis Papanagnou wrote in comp.lang.javascript:

>You can add/remove/enable/disable/change a special <styleelement with
the desired rules; if you have very many matching elements that''ll most
likely be the fastest approach.


Thanks for your quick reply. As a (quite) newbie on the topic I seem to
be still missing something fundamental that is likely apparent to you.

I am saying, among other suggestions, you can add and remove a construct
like

<style type="text/css">
.A { visibility:visible; }
.B { visibility:hidden; }
...
</style>

to the document using methods like createElement and appendChild.
--
Bj?rn H?hrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/


这篇关于隐藏特定类的所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆