Selektor jQuery meminjam aturan penargetan CSS sehingga sangat mudah dipelajari: $('#id'), $('.class'), $('p'), $('ul li:first').
jQuery Selectors
Contoh Kode jQuery jQuery Selectors:
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<style>body { font-family: sans-serif; padding: 20px; }</style>
</head>
<body>
<p class="target">Paragraf dengan Kelas .target</p>
<p>Paragraf Biasa</p>
<button id="btnSorot">Sorot Kelas .target</button>
<script>
$('#btnSorot').click(function() {
$('.target').css({'background-color': '#fca311', 'font-weight': 'bold', 'padding': '5px'});
});
</script>
</body>
</html>
Uji interaksi jQuery di atas dan amati animasi efek DOM secara langsung.