Adding and removing classes
The jQuery library harnesses the power of CSS selectors to let us quickly and easily access elements in a web page. Jquery provides functions to manipulate element attributes.
These methods allow the reading, deleting and updating of classes, hrefs, values, ids and much more. .addClass() adds a specified class to an element. To add a class to a selection this function is called with an argument being the name of the class you wish to add.
When the factory function is used this way we call it a selector.
For example if we want to select all paragraphs with class name is div-block in our demo , Then we will use the code: https://raw.githubusercontent.com/finsweet/jqueryCourse/main/jquery%20functions/ex8.js?actionable=true .removeClass() is the opposite of .addClass() . It removes the specified class from the selected elements.
For example: https://raw.githubusercontent.com/finsweet/jqueryCourse/main/jquery%20functions/ex9.js?actionable=true
$(document).ready(function(){
XT1
});
</script>
Live demo
<style>#buy{color:#baff00;} #buy:hover{text-decoration:underline;} .highlighter{background-color: rgb(186 255 0 / 17%);}</style><div id="minidivpage" class="example-live"><h1 class="heading">This is a heading</h1><div id="popUp" class="pop-up">POP UP DIV</div><h4 class="heading-4">Categories in a webflow list:</h4><ul role="list" class="list"><li>Location</li><li>Position</li><li>Level</li></ul><h3 id="title" class="heading-3">This is a title</h3><div class="highlighter"></div><a id="buy" target="_blank" href="#">Link</a></div>
$(document).ready(function() {
XT1
});
</script>