[英]Jquery Html Element Selector
I have a HTML code like this, 我有这样的HTML代码,
<div class="panel-footer">
<div class="post-activity">
<i class="loading-icon"></i>
<button onclick="ChangeColor(this);">Change Color</button>
</div>
<div class="comments-ch"></div>
</div>
When I write this Jquery code 当我写这个jQuery代码
function ChangeColor(element)
{
$(element).closest(".panel-footer").find(".comments-ch").css("background-color","#CC0000")
}
Not working for class = comments-ch , But If I write this code like this, 不适用于class = comments-ch ,但是如果我这样编写代码,
function ChangeColor(element)
{
$(element).closest(".panel-footer").find(".post-activity").css("background-color","#CC0000")
}
working. 工作。
Summary, first div under the "panel-footer" is OK, but the second/last div NOT OK. 综上所述,“板尺”下的第一个div是确定的,但第二个/最后一个div也不行。
How can i reach the second/last div element? 如何到达第二个/最后一个div元素? Thanks
谢谢
When using a class selector, make sure you specify a period in front. 使用类选择器时,请确保在前面指定句点。
For example, in: 例如,在:
$(element).closest(".panel-footer").find("comments-ch").css("background-color","#CC0000")
Change from find("comments-ch")
to find(".comments-ch")
从
find("comments-ch")
更改为find(".comments-ch")
Try .show()
after setting the CSS: 设置CSS之后尝试
.show()
:
function ChangeColor(element) {
$(element).closest(".panel-footer").find(".comments-ch").css("background-color", "#CC0000").show()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.