如何更改具有某些特殊ID的mudiv div的显示? [英] How to change muitl divs the display which have some special id?

查看:164
本文介绍了如何更改具有某些特殊ID的mudiv div的显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些div

<div id="span1"></div>
<div id="span3"></div>
<div id="span5"></div>
<div id="span7"></div>
.....

id中有"span",如何通过jquery显示或隐藏它们?

There is "span" in the id, How to show or hide them by jquery ?

推荐答案

如果我正确理解了这个问题,这应该可以解决问题.

This should do the trick, if I understand the question correctly.

$('[id*="span"]').hide();

也就是说,更好的方法是将一个类放在要使用同一代码处理的所有元素上,然后使用该类将这些元素作为一组隐藏.

That said, a much BETTER approach would be to put a class on all the elements you want to manipulate with the same code then use the class to hide the elements as a group.

<div id="span1" class"span"></div>
<div id="span3" class"span"></div>
<div id="span5" class"span"></div>
<div id="span7" class"span"></div>

$('div.span').hide();

这要干净得多.

这篇关于如何更改具有某些特殊ID的mudiv div的显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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