The page has a link: <a href="#tab">Profile</a>

And the invisible block: <div id="tab"></div>

How in JS to make that by clicking on a link, first a certain condition is checked and only then a block is displayed? Or just ban the transition

    1 answer 1

    Difficulty in what? Use return false; or preventDefault () (cancels the default action)

     $(function(){ var val = 110; $('a').on('click', function(e){ if(val != 100){ // отмСняСм ΠΏΠ΅Ρ€Π΅Ρ…ΠΎΠ΄ ΠΈΠ»ΠΈ Π½Π΅ выполняСм ΠΊΠ°ΠΊΠΎΠ΅-Π»ΠΈΠ±ΠΎ дСйствиС. e.preventDefault(); // ΠΈΠ»ΠΈ return false; } else { // выполняСм ΠΊΠ°ΠΊΠΎΠ΅-Ρ‚ΠΎ дСйствиС } }); }); 
    • In my case, there is no condition. You just need to block the transition on the element - Jony
    • @Oleg Ponomarchuk, without conditions, but simply block. I showed you how. And I didn’t think about the condition:> ... first a certain condition was checked ... - Deonis