如何使用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>