如何使用document.getElementByTagName和目标特定类名
how to use document.getElementByTagName and target specific class name
这里有代码。
<div class="container">
<div class="accordionHeader">
<h1 onclick="test()"></h1>
</div>
<div class="accordionContent" style="display:none">
<div class="contents"></div>
<div class="contents"></div>
<div class="contents"></div>
</div>
</div>
我想定位并显示/隐藏class="accordionContent"。我试过使用document.getElementByTagName,但我不知道如何针对class="accordionContent"。我不允许使用id。
希望你能帮助我。试着寻找,但没有成功。
使用jquery 可以这样做
$('.accordionContent').show(); //to show
$('.accordionContent').hide(); //to hide
甚至可以切换:)
$('.accordionContent').toggle(); //to hide and show
$('.accordionContent').slideToggle(); //toggle with Animatation
$('.accordionContent').fadeIn(); //fadeIn with Animatation
$('.accordionContent').fadeOut(); //FadeOut with Animatation
选择任何一个,只要你觉得舒服:)
您可以使用getElementByClassName并隐藏/显示accordionContentdiv,如下所示:
document.getElementsByClassName('accordionContent')[0].style.display="show"; // to show
document.getElementsByClassName('accordionContent')[0].style.display="show"; // to hide
相关文章:
- 对一个对象使用reduce可以返回一个没有't在数组中包含目标字母
- 当使用extern和目标JavaScript时,我如何强制Haxe编译器使用require语句
- 如何使用ember.js在操作中传递当前上下文中目标旁边的信息
- 使用javascript将表单提交到iframe目标中
- 当两个单独的单词被放在目标上时,使用Jquery获取一个值
- 是否可以使用Jquery操作窗体的目标窗口
- 如何使用Node.js/MongoDB在AngularJS应用程序中获取特定于目标的数据
- 使用 jQuery 从目标页面而不是当前页面获取元素文本
- jquerymobile:当 mobile.changepage 使用 reloadpage:true 调用时,目标页面
- 当表单目标被遮挡时,如何使用 PHP 提交表单
- 使用next()的jQuery目标元素不起作用
- Three.js:使用变形目标获取更新的顶点
- 使用jquery动态生成的目标内容
- 目标:在使用$(this)之后
- 无法让悬停事件使用 jQuery UI 持续时间参数或 CSS 处理目标元素的同级元素
- 如何使用Javascript实现以下目标
- -jQuery 表单插件 - 使用多个目标/数据
- 莱特币/比特币如何使用javascript获取目标
- 目标c -如何使用JS自动播放Vimeo视频
- 对同一页面中的数据目标模式使用相同的类