How to use Js or jQuery to make it possible to interact with two different objects.

So that when you click on объект_1 , объект_2 and when you click on it (the second object), it will be hidden. If we speak quite simply, we poke at the first, the second appears when clicking on the second, the second hides and so that it can be repeated and not a one-time action (where he did this algorithm and the second time it does not work already until you reload the page)

Closed due to the fact that off-topic by user207618, Igor , 0xdb , Vadim Ovchinnikov , cheops 7 May '18 at 4:20 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • " Learning tasks are allowed as questions only on the condition that you tried to solve them yourself before asking a question . Please edit the question and indicate what caused you difficulties in solving the problem. For example, give the code you wrote, trying to solve the problem "- Community Spirit, Igor, 0xdb, Vadim Ovchinnikov, cheops
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • four
    And have you tried something yourself? - MedvedevDev

1 answer 1

What is your problem?
Enable logic:
On the first element we will hang the search for the second, hide it / show.
On the second one, just turn to yourself (through this , for example) and hide it (there’s no point in processing the display).


Here is an extremely kindly solicited decision:

 $(_ => { $('#obj1').on('click', e => { $('#obj2').toggle(); }); $('#obj2').on('click', function(e) { $(this).hide(); }); }); 
 div { cursor: pointer; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id='obj1'>Show the #2 object</div> <hr /> <div id='obj2'>Click on me for hide</div> 

  • In that that I badly represent how to write all this in the code. - Vasily Pupkin
  • @ VasilyPupkin, If you cannot complete such a simple task - start with the basics of the textbook, here’s a good list. - user207618
  • one
    I would solve my question and not advice with: - Vasily Pupkin
  • four
    @ VasilyPupkin, In this case, I advise you to turn to sites with freelancing services, here we help solve the issue, but do not decide for the author. - user207618