如何选择:后元素使用jquery [英] how to select :after element using jquery
问题描述
Bellow是我的代码。我尝试过。当此弹出窗口出现时,我想使用此关闭按钮关闭整个popbox。
CSS代码
.bigdiv {
display:none;
background-color:#efefef;
box-shadow:10px 10px 10px 100000px rgba(0,0,0,0.4);
border:2px solid #efefef;
width:400px;
height:300px;
position:fixed;
z-index:500;
top:25%;
left:25%;
margin:0 auto;
padding:20px;
}
.bigdiv:after {
cursor:pointer;
content:url('http://static.doers.lk/img/closebox.png');
position:relative;
right:-195px;
top:-310px;
z-index:999;
}
JQUERY
$(。left div)。click(function(){
$(。bigdiv)。show(slow);
$(。bigdiv)。click(function(){
$(。bigdiv)。hide();
});});
HTML
< div class =left>
< div> intro text here< / div>< div>< / div>< div>< / div&
< / div>
< div class =bigdiv>一些内容< / div>
我想选择:元素之后.how使用jquery做什么?
解决方案
我想选择:元素之后使用jquery做什么?
您不能,生成的伪元素不存在于DOM中(可悲的是)。
我们可以这样证明:
CSS:
foo:before {
content:'[Before]'
}
#foo:after {
content:'[After]'
}
HTML:
< body>< div id =foo> Foo< / div>< / body>
JavaScript:
code>(function(){
var msgs = [];
var child;
var div;
for document.body.firstChild;
child;
child = child.nextSibling){
if(child.id){
msgs.push(Child+ child.nodeName + #+ child.id);
}
else {
msgs.push(Child+ child.nodeName);
}
}
div = document.createElement('div');
div.innerHTML = msgs.join(< br>);
document.body.appendChild(div);
})();
从上面得到的页面(如果我们假设
脚本
元素添加到body
在结尾)是:[Before] Foo [After]
儿童DIV#foo
儿童SCRIPT
如您所见,生成的伪元素对DOM来说根本不存在。
Bellow is my codes.what i have tried.when this popup appear i want to use this close button to close entire popbox.
CSS code
.bigdiv{ display:none; background-color:#efefef; box-shadow: 10px 10px 10px 100000px rgba(0, 0, 0, 0.4); border:2px solid #efefef; width:400px; height:300px; position:fixed; z-index:500; top:25%; left:25%; margin:0 auto; padding:20px; } .bigdiv:after { cursor:pointer; content:url('http://static.doers.lk/img/closebox.png'); position: relative; right: -195px; top: -310px; z-index: 999; }
JQUERY
$(".left div").click(function () { $(".bigdiv").show("slow"); $(".bigdiv").click(function () { $(".bigdiv").hide(); }) ; }) ;
HTML
<div class="left"> <div>intro text here</div><div></div><div></div> </div> <div class="bigdiv">some content</div>
I want to select :after elements .how to do that using jquery ?
解决方案I want to select :after elements .how to do that using jquery ?
You can't, generated pseudo-elements don't exist in the DOM (yet, sadly).
We can prove this like so:
CSS:
#foo:before { content: '[Before]' } #foo:after { content: '[After]' }
HTML:
<body><div id="foo">Foo</div></body>
JavaScript:
(function() { var msgs = []; var child; var div; for (child = document.body.firstChild; child; child = child.nextSibling) { if (child.id) { msgs.push("Child " + child.nodeName + "#" + child.id); } else { msgs.push("Child " + child.nodeName); } } div = document.createElement('div'); div.innerHTML = msgs.join("<br>"); document.body.appendChild(div); })();
The page resulting from the above (if we assume the
script
element is added tobody
at the end) is:[Before]Foo[After] Child DIV#foo Child SCRIPTAs you can see, the generated pseudo-elements are just not present at all as far as the DOM is concerned.
这篇关于如何选择:后元素使用jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!