Hello, I’m learning jquery recently and faced the following problem:

$('#leta').click(function() { $('#hide').slideDown('slow'); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <div class='col-lg-4' id='leta'>A</div> <div data-scroll class='col-lg-12' id='hide' style='display:none'>B</div> 

By clicking on 'A' nothing happens in an absolute count.

  • Transferred your code to the snippet - the problem is not observed. - br3t
  • @ br3t can matter in styles? - Dmitry
  • You only need to inspect your #hide in any browser-based debugger. + See errors in the console. - br3t
  • @ br3t I don't understand anything at all I glanced at the error, it says Bootstrap's Javascript requires Jquery But I absolutely connected it - Dmitry
  • MB did you connect it after bootstrap.js? - br3t

1 answer 1

1) I advise you to download jquery from http://jquery.com/ and connect it to the template
2) A little not on the task, but do not use IDs! (#leta, #hide) use classes.
3) <div data-scroll class='col-lg-12' id='hide' style='display:none'>B</div> Inline style is better to transfer to the .css file
4) $ ('# leta'). Click (function () {Use instead of click

 $('#leta').on('click', function() {$('#hide').slideDown();}); 
  • What are bad idshniki? Why then not $('body').on('click', '#leta',...) ? - br3t
  • $ ('body'). on ('click', '#leta', ...)? This is all to what? And the answer to the question: because IDs are rendered longer this time. The second ID is cluttering up the css code. The third is old stuff, because Now the work of the front-end developer is to optimize the css code as much as possible; this is one of the most important tasks - Vyacheslav Kurilov
  • Vyacheslav, the code referred to your item 4 - br3t
  • Understandably, $ ('body'). On ('click', '#leta', ...). it is possible and so, there is no particular difference. how convenient for anyone - Vyacheslav Kurilov
  • You saw 3 lines of code and such "do not use id !!!", what? There are places where they are relevant, there are places where they are not relevant, you need to look at all the markup to know where that is appropriate. And in terms of speed - there are 2 functions in js: "getElementsByClassName" and "getElementById", we notice that in the second case, it is not the collection that is returned, but one element, THINK ... - Oleg Reym