Birdman


#1

What's the diff? Why didn't my code work?

My original code:

var main = function() {
$('img').click(function(){
$(this).toggle("dropdown-menu")
});
}
$(document).ready(main);

Code I found online that work correctly:

var main = function() {
$('img').click(function(e){
$(this).next().toggle();
});
}
$(document).ready(main);

I also found this and it works:

var main = function() {
$('img').click(function() {
$('.dropdown-menu').toggle(250);
});
}
$(document).ready(main);

Why didn't my code and the others did?

Thank you!!!


#2

Hey again Mark,

I'm glad you appreciate my help & don't mind that I'm the one who responds to like all of your questions, because it's me again :)

As best I can tell, your code is telling the computer:

When the image is clicked, toggle the image using the "dropdown-menu" function.

That doesn't work, because dropdown-menu isn't a function, and even if it were, the quotes would goof it up.
The second bit of code:

When the image is clicked, find it's next sibling, and toggle the sibling.

The third bit of code:

When the image is clicked, find .dropdown-menu and toggle it in a quarter second


#3

Ok I get it. I was not reading things the right way. Thanks again!


#4

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