如何使用jQuery操作CSS伪元素:: before和:: after?
使用hover()函数处理CSS伪元素。您可以尝试运行以下代码来学习如何操作CSS伪元素-
示例
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('span').hover(function(){
$(this).addClass('change').attr('data-content','bar');
});
});
</script>
<style>
span.change:after {
content: attr(data-content) ' This is demo text.';
}
</style>
</head>
<body>
<p>Place cursor below...</p>
<span>foo</span>
</body>
</html>热门推荐
8 医政科祝福语简短
10 18岁简短祝福语经典
11 18岁祝福语搞笑简短
12 生日贺卡祝福语 简短独特
13 新娘上头祝福语大全简短
14 入学祝福语简短走心
15 宝子生日祝福语简短
16 3岁孩子祝福语简短
17 叔叔生日祝福语简短励志
18 俄语祝福语贺卡文案简短