<p id="highlightText">Click the button to highlight me!</p>
<button id="addBtn">Add Highlight</button>
<button id="removeBtn">Remove Highlight</button>
<style>
.highlight {
background-color: yellow;
font-weight: bold;
}
</style>
<script>
$(document).ready(function(){
$("#addBtn").click(function(){
$("#highlightText").addClass("highlight");
});
$("#removeBtn").click(function(){
$("#highlightText").removeClass("highlight");
});
});
</script>
.addClass() → Adds CSS class..removeClass() → Removes CSS class.
Leave a Reply