Need help regarding jQuery | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Need help regarding jQuery

actually i was working my code https://code.sololearn.com/W3I8vzwC5p7c/?ref=app and i added an independent close button on the profile section the click function is working there but the profile section is not closing... earlier i was using jquery toggleClass() function that worked fine for me i used "toggleClass('active')" and after adding that close button (not the main close button!... the profile close button...) i used removeClass('active') function on the close button which is not working for me

19th May 2018, 6:20 PM
Ayush
Ayush - avatar
3 Answers
+ 8
I got a solution $(".close-profile").click(function(e) { $('.footer').removeClass('active'); e.stopPropagation(); }) the 'stopPropagation()' works well for me... as this prevents the clicking of any parent or children elements and clicks only the element specified... now check the code the close button is working... https://code.sololearn.com/W3I8vzwC5p7c/?ref=app
20th May 2018, 10:44 AM
Ayush
Ayush - avatar
+ 11
$('.footer').click(function(e) { if (e.target !== this) return; .... }));
19th May 2018, 6:48 PM
Toni Isotalo
Toni Isotalo - avatar
+ 9
Because $('.footer').click() method is executed. It removes the class and then adds it again so it never gets removed.
19th May 2018, 6:45 PM
Toni Isotalo
Toni Isotalo - avatar