jQuery select div with ID and class

烈酒焚心 提交于 2019-12-19 04:15:24

问题


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?


回答1:


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

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


来源:https://stackoverflow.com/questions/11602870/jquery-select-div-with-id-and-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!