In the below code, I try to display content: text with jquery.
If I delete :before
it works! Why doesn't jQuery allow that while javascript do that.
This post (7 years ago) talks about my problem, but it works around the problem without giving a simple solution.
Today there is no simple solution to target :before
?
thanks for your help
$(document).ready(function() {
$("div").mouseenter(function() {
$("li:nth-child(2):before").show();
});
$("div").mouseleave(function() {
$("li:nth-child(2):before").hide();
});
});
li {
display: none;
}
li:before {
content: 'Show me';
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<li>This is a paragraph.</li>
<li>This is a second paragraph.</li>
</ul>
<div style="width:30px; height:30px; background:black;cursor:pointer;position:absolute; top:50px;"></div>