As someone who is relatively new to JQuery, I have a question regarding the .on() function. Take this example:
$('div').on('click', function() {$(this).toggleClass('show-description');});
This code selects all the 'div' elements in my HTML file and listens for a click event. When clicked, it will toggle the 'show-description' class on and off for the last div that was clicked on.
<div class="show-description"> ......</div>
Now, what if I only want to target a specific class within a div tag for my event listener?
I attempted the following:
$('div.about').on('click', function() {$(this).toggleClass('show-description');});
In my HTML, it looks like this:
<body>
<div class="clearfix">
<div class="column">
<ul>
<li id='about'> <span>About Me</span> </li>
......
</div>
</div>
However, my 'show-description' styles don't seem to be triggering. I've done some research on the .on() method from the API documentation and checked Stack Overflow, but I'm still stuck. I'm not expecting a direct solution, just hoping for a helpful nudge in the right direction.
Thank you.