Hiding element inside a menu

Asked

Viewed 30 times

0

I have a menu like this..

<div class="btn-group">
    <button type="button" class="btn btn-danger vermDigifred btn-xs dropdown-toggle glyphicon glyphicon-pencil" data-toggle="dropdown"> </button>                                           

    <ul class="dropdown-menu" role="menu">
        <li  ><a id="btnExcluirRegistro" ng-click="excluirDistritos(dis)"><span class="glyphicon glyphicon-trash"></span> Excluir registro</a></li>
        <li > <a id="btnAlterarRegistro" data-toggle="modal" data-target="#modalAlterarDistrito" ng-click="alterarDistritos(dis)" ><span class="glyphicon glyphicon-edit"></span> Alterar registro</a></li>
    </ul>
</div> 

I want to do a function on Js to hide the tag a if, for example, delete =1

  • What would be excluir? A variable in Javascript? And what have you tried to do?

  • @Andersoncarloswoss yes, delete is a Javascript variable that gets a value that can be 0 or 1, so if it is 1 I would like that tag to be hidden

  • The two or s[the one? If one, which one? And I insist: can you ask the question the JS you have tried to do? This will make it easier to identify where you’re struggling.

  • 1

    I’m particularly confused, but the two tags are a to delete and to change if you click delete want to hide both? this menu is in a row? that is to say it has several menus of this on a page?

1 answer

2


This code must do what you are wanting, it will hide all tags a page.

const esconder = function(excluir) {
    if (excluir === 1){
        let a = document.getElementsByTagName('a');
        for (let i = 0; i < a.length; i++){
            a[i].style.visibility = "hidden";
        }  
    }
};

Remembering that you need to define where this comes from excluir

Browser other questions tagged

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