jQuery select div with ID and class

Sweepster picture Sweepster · Jul 22, 2012 · Viewed 10.5k times · Source

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?

Answer

Engineer picture Engineer · Jul 22, 2012

Use article instead of input,and id instead of name:

$('article[id^="post-"].like').hide();