<!DOCTYPE html> <html> <head> <title></title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script language="javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <style type="text/css"> .active { background: blue; height: 40px; line-height: 40px; color: white; } </style> <script language="javascript"> $(document).ready(function(){ $("div:has(p)").addClass('active'); }); </script> </head> <body> <div> <p class="my-class">Messi là cầu thủ xuất sắc nhất thế giới</p> </div> <div> <h3>Không có thẻ p</h3> </div> </body> </html>