Demo selector tìm theo đúng giá trị thuộc tính
RUN
<!DOCTYPE html> <html> <head> <title>Đổi màu nhé</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script language="javascript" src="http://code.jquery.com/jquery-2.0.0.min.js"></script> <style> body{ margin: 20px; } a{display: block; border:solid 1px blue; padding: 5px; height: 30px; line-height: 30px; text-decoration: none; margin-bottom: 20px} .selected { border: solid 1px; color: white; background: blue } </style> <script language="javascript"> $(document).ready(function() { $('#button').click(function() { $('a[title="freetuts"]').addClass('selected'); }); }); </script> </head> <body> <a href="#" title="trang freetuts">title = trang freetuts</a> <a href="#" title="websitefreetuts">title = websitefreetuts</a> <a href="#" title="freetuts">title = freetuts</a> <a href="#" title="hoc-lap-trinh-online-tai-freetuts"> title = hoc-lap-trinh-online-tai-freetuts</a> <button id="button">Kiểm tra</button> </body> </html>
PHÓNG TO