Verify link depending on content start query

1

I need to load a "fake loader" when a menu link is triggered, but in this menu some links are empty <a href="javascript:;"> or <a href="#"> , I need to only identify these via javascript and not open the loader. >

I can not add anything in the menu (id, class, etc ...).

$( "a" ).click(function() {
  $( "#loader" ).fadeIn( "slow" );
});
#loader{ width: 100%; height:100%; display: none; background-color:rgba(255,255,255,0.6); position: fixed; top: 0; left: 0; z-index: 2 }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="loader"><img src="images/loader.gif" width="100px" height="100px" style="margin-left: 45%; margin-top: 20%;" /></div> 


<nav>
<ul>
  <li><a href="#">Vazio 1</a> <- Não pode Funcionar</li>
  <li><a href="javascript:;">Vazio 2</a> <- Não pode Funcionar</li>
  <li><a href="linkcerto">Link correto</a></li>
</ul>
</nav>

The reason for the problem is the backend developer of the site I'm messing around with, so I can not manipulate the source code directly, just in java-script.

    
asked by anonymous 05.09.2017 / 21:50

2 answers

1

Make a condition to call the loader ...

$( "a" ).click(function() {
if($(this).attr("href") != "javascript:;" && $(this).attr("href") != "#") {
  $( "#loader" ).fadeIn( "slow" );
}
});
#loader{ width: 100%; height:100%; display: none; background-color:rgba(255,255,255,0.6); position: fixed; top: 0; left: 0; z-index: 2 }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="loader"><img src="images/loader.gif" width="100px" height="100px" style="margin-left: 45%; margin-top: 20%;" /></div> 


<nav>
<ul>
  <li><a href="#">Vazio 1</a> <- Não pode Funcionar</li>
  <li><a href="javascript:;">Vazio 2</a> <- Não pode Funcionar</li>
  <li><a href="linkcerto">Link correto</a></li>
</ul>
</nav>
    
05.09.2017 / 22:31
1

Rodrigo. Try it on your JS (I do not know if it will work, I have not tested it.

$( "a" ).click(function() {
     if (("a").val() != "Vazio 1" || ("a").val() != "Vazio 2")
     {
        $( "#loader" ).fadeIn( "slow" );
     }
});
    
05.09.2017 / 22:27