Remove <li> elements that does not contain a certain “href” value inside <a>

I have bought a wordpress theme called Salient : http://themenectar.com/demo/salient-frostwave/home-basic/

It has this AJAX search (little search icon in the menu) and I want to remove any search results from the list that has a certain href value, say “portfolio” in it.

Read More

I have tried with adding following code as a “raw html element” inside script tags in the page builder plugin but it did not work

$('a[href*="portfolio"]').css.({display:"none"})

How to I implement this on wordpress?

Update :

Thanks for all the answers. There was a “.” after “css” and the correct line should be :

$('a[href*="portfolio"]').css({display:"none"})

Now I need to know how to select and hide all other elements that does not contain “portfolio”. i.e. the end result will only have the items with “portfolio” in it.

I tried

href!="portfolio"

But it does not select any because != matches the exact and only “portfolio” where as my “portfolio can be anywhere in the link.

Related posts

6 comments

  1. To hide all elements that does NOT contain the word portfolio:

    $('a:not([href*="portfolio"])').css({display:"none"});
    
  2. Why everybody write another code? There is a dot after css function, clear it. Replace with :

    $('a[href*="portfolio"]').css({display:"none"})
    
  3. You probably don’t have jquery, you can import it by adding this to HTML

    <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
    

    So you can use your code $('a[href*="portfolio"]').css.({display:"none"});

    Or you can use javascript (adapt as needed):

    var elem = document.getElementById("yourId");
    elem.parentElement.removeChild(elem);
    

Comments are closed.