img

Hello! Problem, I want a menu to open by clicking on the picture, I made the menu myself, I just need to change the position of the menu by clicking on the picture.

Hi @Javer - can you share more details like a screenshot or what your current markup/code looks like?

Cheers,
Kirupa :grinning:

I have already removed the script because it did not work, I did it as in the book on chapter 30

<a href="#" class="logo" id="setting"><img src="/Users/daniil/Documents/qwins/png/imgonline-com-ua-Resize-xxZoL2fDi8Sp.png"></a>

<script>
     let setting-menu = document.querySelecor("#setting");
     setting-menu.addEvenListener("click",menu_open, false);

     function menu_open(e){
       document.logo.style.border = "20px solid darkred";
     }

    </script>

here is the code. relying on a book

@kirupa

When you check in the console, what error are you seeing? Here is a guide on how to work with the console: Console Logging Basics

Now, one thing that seems off is the spelling of your properties:

  • querySelecor should be querySelector
  • addEvenListener should be addEventListener

Once you make these spelling updates, see if your code works. If it still doesn’t work, check the Console (using the guide from the earlier link if you aren’t sure how to do that) and let me know what errors you see.

Cheers,
Kirupa

writes no errors, but the code still does not work exactly
@kirupa

Did you fix the spelling of the misspelled properties? Can you paste a screenshot of what it is that you currently are seeing in your browser when you try to run this app?

throw something else? @kirupa

When I ran the snippet you posted, the Console showed me another error:

It turns out you can’t name a variable as setting-menu where you have the - character. Also, this line “document.logo.style.border” doesn’t work either. What does document.logo refer to here?

Here is a working example where clicking on the image gives it a border: https://codepen.io/kirupa/pen/rNJrpYj

Take a moment and see where the book’s instructions and what you have differ. JavaScript isn’t very forgiving of misspellings and syntax errors. You have to ensure your code is exactly as specified.

Hopefully this helps :slight_smile:

helped, thanks.
And how to make it so that when you click in an empty area, this frame disappears in the picture? @kirupa

You can listen for a click event on the body element and essentially undo the inline style you are setting on the image.

Two tutorials that can help you out:

Good afternoon, the problem is not solved. I don’t understand how to make it so that when you click on the picture, the property of another class changes, that is, I made a menu and indicated an indent from the right -100%, it is necessary that when you click on the picture this indent disappears (that is, it was 0%), I think I clearly explained . Sorry for such stupid questions :slight_smile:

@kirupa

This tutorial sounds like it can help you out: Creating a Smooth Sliding Menu | KIRUPA

What it highlights and what you describe trying to do are very similar :grinning: