jQuery select div with ID and class
-
22-06-2021 - |
Domanda
I have the following:
<article id="post-43" class="like"></article>
<article id="post-56" class="like"></article>
<article id="post-78" class="dislike"></article>
<article id="bob" class="like"></article>
I want to hide all the articles that have ID beginning with "post-" that also have the class "like" using jQuery.
I have tried this:
$('#show_likes').on('click', function() {
$('input[name^="post-"].like').hide();
});
But it doesn't work.
Can someone help?
Soluzione
Use article
instead of input
,and id
instead of name
:
$('article[id^="post-"].like').hide();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow