Can't figure out why my id isn't being targeted by my function


#1

https://www.codecademy.com/courses/web-beginner-en-GfjC6/0/3?curriculum_id=50a3fad8c7a770b5fd0007a1#

Oops, try again. Did you target the 4th li child of the ordered list? Check the Hint if you need help.

``` // Relevant HTML
 <ol>
    <li>Start with the function keyword</li>
    <li>Inputs go between ()</li>
    <li>Actions go between {}</li>
    <li id= "yolo">jQuery is for chumps!</li>
</ol>

// Relevant Jquery

$(document).ready(function() {
    var $target = $("#yolo");
    (function() {
        $target.fadeOut('fast');
    });
});

‘’’


#2
 (function() {
        $target.fadeOut('fast');
    });

why are you using anonymous function for it?

you can directly write

$target.fadeOut('fast');

and if you really want to use that function then call it at the end

 (function() {
        $target.fadeOut('fast');
    })(); // () calls that function

#3

Oh i forgot i had to call it, i percieved writing the function inside document.ready as sufficient for it to trigger itself on page loading.

Thank you very much for your quick answer, was really helpful

PS: i want to use unecessary anonymous function beacause i don’t know what i’m doing yet, and i like to fail in every way possible until i can write things even in uneccessary complex fashion as soon as i can/find how to, so as not to fail in trickier settings later on. Some mentality i got from training to play piano, where i didn’t settle for being able to clear a performance - instead i trained for being unable to fail whatever i was playing


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.