Check link depending on content starts query

Asked

Viewed 37 times

1

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

I cannot 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>
<div id="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 back-end developer of the site I’m touching has simply disappeared, so I can’t move the source code directly, only in java-script.

2 answers

1

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

$( "a" ).click(function() {
     if (("a").val() != "Vazio 1" || ("a").val() != "Vazio 2")
     {
        $( "#loader" ).fadeIn( "slow" );
     }
});
  • I don’t quite understand what you want to do. , but in your JS you’re taking the link to all the elements that have the <code>a</code> tag so it fires. Put an ID on the items and call the specific ID. ?

  • I think it would be more interesting if you demonstrate (via code) the solution

  • So, the problem is that I have no way to edit "html" because the back-end blocked the change of the files in ftp. I am only allowed to edit the ". js" and ". css". Other items that already have ID blocked, the links in question cannot add ID, class or any other element. For this reason I need to identify what has the mentioned urls and not activate the function.

  • Rodrigo.There is no way to take this file from FTP, make the change and replace?

  • It didn’t work. An important thing is that the words "empty 1" and "empty 2" are symbolic, the links are not real. , using your code would be kind of like this:

  • $( "a" ).click(Function() { if (("a").val() != "#" || ("a").val() != "javascript:;") { $( "#Loader" ).fadein( "slow" ); } });

  • Meso so did not work.

Show 2 more comments

1


Make a condition to call the Oader...

$( "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>
<div id="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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.