层次选择器说明

2016-01-20  本文已影响47人  crocodile_b

jQuery的层选择器$("ancestor descendant")和$("parent>child")举例说明

<div>This is <strong>very</strong> important.</div>
<div>This is <em>really <strong>very</strong></em> important.</div>

以上是html。运行后在浏览器里是看到


1.JPG

这样的样式,为了容易看到效果,我们不妨就尝试用添加css颜色来试一下

如果运行

$("div strong").css("color","red");

就是把div的后代元素strong变为红色。运行后是


2.JPG

如果运行

$("div>strong").css("color","blue");

就是把div的子元素strong变为蓝色。运行后是

3.JPG
上一篇 下一篇

猜你喜欢

热点阅读