Remove links that have a certain string with Jquery

Asked

Viewed 26 times

1

Good night, good people...

Good my doubt and the following, I have a list of links...

<ul>
<li><a href="baixar.php?musica=teste-ativo.mp3">Musica 1</a></li>
<li><a href="baixar.php?musica=teste-desativado.mp3">Musica 2</a></li>
<li><a href="baixar.php?musica=teste-ativo.mp3">Musica 3</a><li>
<li><a href="baixar.php?musica=teste-desativado.mp3">Musica 3</a></li>
</ul>

well, now I wanted q only links that have the string "disabled" in the url, were hidden, with Hide(); for example

Att... Thank you

1 answer

2


You can use the "attribute contains selector" jQuery to select the links that contain the "disabled string":

$("li > a[href*='desativado']").hide();

Note that this will hide the text, but the list item keeps appearing. What you probably want is to remove the elements from the list, which you can do using the remove() (example in Jsfiddle):

$("li > a[href*='desativado']").parent().remove();
  • opa thanks guy! it worked! taking advantage! we will vary the question! and to remove the links that have not "disabled" without using your code above? in case every link q has not been "disabled" using an if condition

  • ah man thanks! already managed to do with php! I get better! but still thank you!

Browser other questions tagged

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