如何使用jQuery 操作CSS偽元素::before 和::after?
使用hover()函式操作CSS偽元素。您可以嘗試執行以下程式碼來學習如何操作CSS偽元素−
示例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/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>
廣告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP