jQuery选择具有ID和类的div [英] jQuery select div with ID and class
本文介绍了jQuery选择具有ID和类的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下内容:
<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>
我想使用jQuery隐藏所有ID以"post-"开头的文章,以及所有具有"like"类的文章.
I want to hide all the articles that have ID beginning with "post-" that also have the class "like" using jQuery.
我已经尝试过了:
$('#show_likes').on('click', function() {
$('input[name^="post-"].like').hide();
});
但这是行不通的.
有人可以帮忙吗?
推荐答案
使用article
代替input
,并使用id
代替name
:
Use article
instead of input
,and id
instead of name
:
$('article[id^="post-"].like').hide();
这篇关于jQuery选择具有ID和类的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文