I'm fairly new to JQuery, was wondering about the .on() function. For example:
$('div').on('click', function() {$(this).toggleClass('show-description');});
the first bit of code is selecting all the 'div' elements within my HTML file and is listening for a click event. Then, it will toggle my 'show-description' class 'on' and 'off' for the last div I clicked on.
<div class="show-description"> ......</div>
What if I want to specify only a specific class I defined within a div tag to listen for my event?
I've tried:
$('div.about').on('click', function() {$(this).toggleClass('show-description');});
Where I have defined within HTML:
<body>
<div class="clearfix">
<div class="column">
<ul>
<li id='about'> <span>About Me</span> </li>
......
</div>
</div>
Yet I don't get my 'show-description' declarations to activate . I've already tried reading up on the API .on() method, as well as going through Stack and can't seem to find anything to help with this. I'm not looking for direct answer just a nudge in the right direction.
Thanks.
<div class="about">
on your code?$("div.column").on("click", "#about", function(){ })
, should work. I tried it, but I usealert("test")
inside that click listener, and it works.