Code passing but doesn't work -- Hide Other Descriptions


#1

Passed lesson to hide other descriptions, but now no descriptions are showing when I click. What is wrong with my code?

var main = function () {
$('.article').click (function () {
$('.description').hide();
$(this).children('.description').show();

});
}


#2

Hey Jenny,

You need to call main() - at the end of your code, add this line:

$(document).ready(main);

This will call the main function once the page has loaded :slight_smile:


#3

I have the same problem as Jenny and I have a call for main() at the bottom of my code.

When submitting the code it passes, but it doesn't work when trying it out myself.

var main = function() {
    $('.article').click(function(){
        $('.article').removeClass('.current');
        $('.description').hide();
        $(this).addClass('.current');
        $(this).children('.description').show();


        });
    };

$(document).ready(main);

I want to understand what's going on here

EDIT: I found my problem

$('.article').removeClass('.current');
and
$(this).addClass('.current');

I removed the . before current

:smiley:

Now I see we didn't have the same problem after all.


#4

My question is why can't we use the . before the current as surely, to access the css elements then we should use the dot? :confused:


#5

@steve80 I answered that in this post:

Let me know if you still have questions about it! :slight_smile: