Inserted Code Does Not Change the Display


#1



https://www.codecademy.com/en/courses/web-beginner-en-4hxyb/0/3?content_from=make-an-interactive-website%3Ajquery-events


When I insert the code, it does not actually change anything on the newsfeed display. I believe I entered the correct code to show the description when the article is clicked on, but it does not work. When I try it and when I hit "Save and Submit" it accepts it as the correct code and move on to the next lesson.

It is not specific to this exact exercise, so I am wondering if it could be a browser issue?


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


#2

Hi @mguyer,

$(this) references a jQuery object, the current element jQuery is interacting with. $('this') references the (nonexistent) <this> HTML tag. So if you change line 3 to reference the appropriate thing, your code will work :slight_smile:


#3

@mguyer,
as addition to the article of @zystvan,

With $() you are using the jQuery-Selector.....
To select a HTML-Element which carries a class attribute like class="article"
you have to pre-pend the class-name-string with a dot like
$('.article')

Thus you would have had to use

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

===============================================

If a HTML-Element is carrying the id attribute like id="unique"
and you wanted to select to corresponding HTML-Element with the jQuery-Selector
you will have to pre-pend the id-attribute-name-string with a hash ( # )
you would use
$('#unique')

Play around with
http://www.w3schools.com/jquery/trysel.asp

===============================================

Reference::

google search
class site:jquery.com
https://api.jquery.com/category/selectors/
http://api.jquery.com/class-selector/
https://api.jquery.com/element-selector/
http://www.w3schools.com/jquery/jquery_ref_selectors.asp
http://www.w3schools.com/jquery/trysel.asp

what is CSS explained site:developer.mozilla.org
https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started/What_is_CSS


#4

Thanks so much. That helps a lot!


#5

Thanks! I appreciate the help.