查找元素是否只包含一个元素,如果为true则隐藏父元素
Finding if a element just holding one element and hide parent element if true
我需要一个javascript而不是jquery解决方案。任何帮助都会很棒。我需要检查p标签是否只有br标签,如果是,则隐藏p标签。
<blockquotes>
<p>
<br> </br> < so if this is the only element then hide the p tag
</p>
</blockquotes>
试试这个。
function hidePTags() {
var pTags = document.getElementsByTagName('p');
for (var i = 0; i < pTags.length; i++) {
if (pTags[i].children.length == 1 && pTags[i].children[0].tagName == "br") {
pTags[i].style.visibility = "hidden";
}
}
}
相关文章:
- 指令的模板必须只有一个根元素:With restrict E&替换true
- Jquery:当两个或多个条件为true时,选择一个元素
- 检查一个元素是否有一个类与另一个类总是返回true
- 仅显示选中 = true 的元素
- Jquery-(ajax async:true)元素大小没有响应
- contenteditable=true元素的文本建议
- 为什么当事件变为“true”时,我的 JQuery 函数没有在克隆的元素上触发
- 延迟似乎不会在元素上的 Stop(true, true) 之后延迟
- replace:true 如何与元素指令一起使用
- 如何选择两个元素的文本与内容可编辑 = true
- 带有 contenteditable=true 的 pre 标记 - 元素的 text() 内容中不会保留新行
- 无法手动将 DIV 元素上的可见性设置为 true.“TH:IF”问题
- 如果条件为 true,则向父元素添加类
- 如果两个元素使用jquery中的运算符具有相同的类,则返回true
- ng使用内联编辑重复,如何使第一个(或最后一个)元素的editmode=true
- 查找元素是否只包含一个元素,如果为true则隐藏父元素
- 当超过0%的元素在视口/窗口中时返回true
- 当将两个变量设置为相同的dom元素时,Jquery语句的值不为true
- 应该在附加克隆元素时使用clone(true),还是使用on()和clone(false)
- 在条件求值为true时获取元素(扩展ElementArrayFinder)