How to select nested HTML li and keep it hidden

how can i keep the li with the iconsrc="/_layouts/15/images/delitem.gif"

image hidden as this div is injected by the first side and i am a proponent trying to hide it.

$("<style> what will go here ???? { display: none; }</style>").appendTo(document.documentElement);

      

How to select a list item with iconsrc="/_layouts/15/images/delitem.gif"

from a document.

<div class="ms-core-menu-box ms-core-menu-hasIcons ms-core-defaultFont ms-shadow" title="" dir="ltr" contenteditable="false" style="top: 0px; position: absolute; visibility: visible; left: -129px; width: 127px;" flipped="false">
    <ul class="ms-core-menu-list">
        <li type="option" text="Delete" onmenuclick="spgridcontainer_WPQ2_rowcontextmenu_onclick(0);" iconsrc="/_layouts/15/images/delitem.gif" iconalttext="Delete" enabled="true" checked="undefined" id="mp43_0_0" class="ms-core-menu-item">
            <a class="ms-core-menu-link" id="mp43_0_0_Anchor" href="javascript:;" onclick="return false;" title="Delete">
                <div class="ms-core-menu-icon">
                    <img src="/_layouts/15/images/delitem.gif" alt="Delete" title="Delete" id="mp43_0_0_ICON">
                </div>
                <div class="ms-core-menu-label" id="">
                    <span class="ms-core-menu-title">Delete</span>
                    <span></span>
                </div>
                <span class="ms-accessible"></span>
                <div></div>
            </a>
        </li>
    </ul>
</div>

      

The period keeps the Delete button hidden as the list is entered into the page.

+3


source to share


3 answers


Keep this with css attribute selectors:



li[iconsrc="/_layouts/15/images/delitem.gif"] {
    display:none;
}
      

<ul>
    <li iconsrc="/_layouts/15/images/delitem.gif">
        <img src="/_layouts/15/images/delitem.gif" alt="Delete" title="Delete" id="mp43_0_0_ICON" />
    </li>
    <li>
        <img src="/_layouts/15/images/adasdasfafsdfs.gif" alt="sdfsdfsdf" title="Blablalbavbaab" id="fsdfsdfsdf"/>
    </li>
</ul>
      

Run codeHide result


+1


source


you can use list id attribute on style tag to keep it hidden:



<style>
  li#mp43_0_0 {
      display: none;
  }
</style>

      

0


source


you can try the following:

$(document).ready(function(){
$('ul li').each(function(idx, li) {
 if($(li).attr('iconsrc') =='/_layouts/15/images/delitem.gif'){
   $(li).hide();
 }
});
});

      

0


source







All Articles