J'essaie de cacher les éléments (li?) Dans un menu de lancement rapide, où il est dit «Avantages cachés», le HTML est;

<div class=" noindex ms-core-listMenu-verticalBox" id="zz13_idPDPQuickLaunch">
    <ul class="root ms-core-listMenu-root static" id="zz14_RootAspMenu">
        <li class="static">
            <a class="static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode" href="/sites/pwa/">
                <span class="additional-background ms-navedit-flyoutArrow">
<span class="menu-item-text">Defra Benefits Dev</span></span>
            </a>
            <ul class="static">
                <li class="static"><a class="static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode" href="/sites/pwa/"><span class="additional-background ms-navedit-flyoutArrow"><span class="menu-item-text">Project Information</span></span></a></li>
                <li class="static selected"><a class="static selected menu-item ms-core-listMenu-item ms-displayInline ms-core-listMenu-selected ms-navedit-linkNode" href="/sites/pwa/"><span class="additional-background ms-navedit-flyoutArrow"><span class="menu-item-text">Benefits</span><span class="ms-hidden">Currently selected</span></span></a></li>
                <li class="static"><a class="static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode" href="/sites/pwa/"><span class="additional-background ms-navedit-flyoutArrow"><span class="menu-item-text">Benefits HIDDEN</span></span></a></li>
                <li class="static"><a class="static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode" href="/sites/pwa/"><span class="additional-background ms-navedit-flyoutArrow"><span class="menu-item-text">Benefits HIDDEN</span></span></a></li>
            </ul>
        </li>
        <li class="static"><a class="static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode" href="javascript:PDPInfrastructure.NavigateWSSPage(0,true)"><span class="additional-background ms-navedit-flyoutArrow"><span class="menu-item-text">Project Site</span></span></a></li>
    </ul>
</div>

J'ai essayé ce qui suit sans succès

<script>
$(document).ready(function() {
    $("#zz13_idPDPQuickLaunch *:contains('Benefits HIDDEN')").hide ();
});
</script> 
0
Cybacor 6 avril 2020 à 20:52

3 réponses

Étant donné que de nombreux éléments contiennent ce texte (pas seulement les éléments span dans lesquels il se trouve, mais le li dans lequel se trouve span, son ul, etc., etc. - même - l'élément #zz13_idPDPQuickLaunch lui-même), vous devez être plus précis avec votre sélecteur.

Idéalement, ajoutez une classe ou quelque chose à l'élément le plus profond que vous souhaitez masquer. Mais vous pouvez aussi le faire structurellement. Par exemple, si vous souhaitez masquer les li:

$(document).ready(function() {
    $("#zz13_idPDPQuickLaunch li ul li.static:contains('Benefits HIDDEN')").hide ();
});

Exemple en direct:

$(document).ready(function() {
    $("#zz13_idPDPQuickLaunch li ul li.static:contains('Benefits HIDDEN')").hide ();
});
<div class=" noindex ms-core-listMenu-verticalBox" id="zz13_idPDPQuickLaunch">
    <ul class="root ms-core-listMenu-root static" id="zz14_RootAspMenu">
        <li class="static">
            <a class="static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode" href="/sites/pwa/">
                <span class="additional-background ms-navedit-flyoutArrow">
<span class="menu-item-text">Defra Benefits Dev</span></span>
            </a>
            <ul class="static">
                <li class="static"><a class="static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode" href="/sites/pwa/"><span class="additional-background ms-navedit-flyoutArrow"><span class="menu-item-text">Project Information</span></span></a></li>
                <li class="static selected"><a class="static selected menu-item ms-core-listMenu-item ms-displayInline ms-core-listMenu-selected ms-navedit-linkNode" href="/sites/pwa/"><span class="additional-background ms-navedit-flyoutArrow"><span class="menu-item-text">Benefits</span><span class="ms-hidden">Currently selected</span></span></a></li>
                <li class="static"><a class="static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode" href="/sites/pwa/"><span class="additional-background ms-navedit-flyoutArrow"><span class="menu-item-text">Benefits HIDDEN</span></span></a></li>
                <li class="static"><a class="static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode" href="/sites/pwa/"><span class="additional-background ms-navedit-flyoutArrow"><span class="menu-item-text">Benefits HIDDEN</span></span></a></li>
            </ul>
        </li>
        <li class="static"><a class="static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode" href="javascript:PDPInfrastructure.NavigateWSSPage(0,true)"><span class="additional-background ms-navedit-flyoutArrow"><span class="menu-item-text">Project Site</span></span></a></li>
    </ul>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Cela signifie que vous souhaitez uniquement masquer les éléments contenant ce texte si ce sont des éléments li à l'intérieur d'un ul qui est à l'intérieur d'un li qui est à l'intérieur de l'élément # zz13_idPDPQuickLaunch` .

0
T.J. Crowder 6 avril 2020 à 17:58

Vous devez boucler chaque élément "li" et vérifier d'abord le texte à l'intérieur. Essaye ça:

$(function(){

            var menu_items = $("#zz14_RootAspMenu").find("li");
          menu_items.each(function(idx,el){
            var current_text = $(el).find('.menu-item-text').text();

            if(current_text == "Benefits HIDDEN"){
              $(this).hide();
            }
          })


        });
0
Elman Huseynov 6 avril 2020 à 18:00
$('.menu-item-text').each(function() {
  this.textContent.trim() === 'Benefits HIDDEN' && $(this).closest('li').hide();
});
<div class="noindex ms-core-listMenu-verticalBox" id="zz13_idPDPQuickLaunch">
  <ul class="root ms-core-listMenu-root static" id="zz14_RootAspMenu">
    <li class="static">
      <a class="static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode" href="/sites/pwa/">
        <span class="additional-background ms-navedit-flyoutArrow">
<span class="menu-item-text">Defra Benefits Dev</span></span>
      </a>
      <ul class="static">
        <li class="static"><a class="static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode" href="/sites/pwa/"><span class="additional-background ms-navedit-flyoutArrow"><span class="menu-item-text">Project Information</span></span></a></li>
        <li class="static selected"><a class="static selected menu-item ms-core-listMenu-item ms-displayInline ms-core-listMenu-selected ms-navedit-linkNode" href="/sites/pwa/"><span class="additional-background ms-navedit-flyoutArrow"><span class="menu-item-text">Benefits</span><span class="ms-hidden">Currently selected</span></span></a></li>
        <li class="static"><a class="static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode" href="/sites/pwa/"><span class="additional-background ms-navedit-flyoutArrow"><span class="menu-item-text">Benefits HIDDEN</span></span></a></li>
        <li class="static"><a class="static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode" href="/sites/pwa/"><span class="additional-background ms-navedit-flyoutArrow"><span class="menu-item-text">Benefits HIDDEN</span></span></a></li>
      </ul>
    </li>
    <li class="static"><a class="static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode" href="javascript:PDPInfrastructure.NavigateWSSPage(0,true)"><span class="additional-background ms-navedit-flyoutArrow"><span class="menu-item-text">Project Site</span></span></a></li>
  </ul>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
1
Roko C. Buljan 6 avril 2020 à 18:12