如何使用jQuery [duplicate]显示特定的div

时间:2022-11-16 10:47:45

This question already has an answer here:

这个问题已经有了答案:

<div class="companyname" data-companyname="abc" ></div>
<div class="companyname" data-companyname="xyz" ></div>
<div class="companyname" data-companyname="pqr" ></div>

I need show only data-companyname="abc" div only....so i used following way in jQuery

我需要只显示data-companyname =“abc”div只有....所以我用jQuery遵循的方式

$(".companyname").attr('abc').show();

How to get this?

这个怎么走吗?

3 个解决方案

#1


2  

$('div[data-companyname="abc"]').show()
.companyname {
  display: none
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="companyname" data-companyname="abc">1</div>
<div class="companyname" data-companyname="xyz">2</div>
<div class="companyname" data-companyname="pqr">3</div>

use the attr selector

使用attr选择器

#2


1  

You need to use attribute equals selector

您需要使用属性= selector

Selects elements that have the specified attribute with a value exactly equal to a certain value

选择具有指定属性且值完全等于某个值的元素

$(".companyname[data-companyname=abc]").show();

$(".companyname[data-companyname=abc]").show();
.companyname{display:none}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="companyname" data-companyname="abc" >abc</div>
<div class="companyname" data-companyname="xyz" >xyz</div>
<div class="companyname" data-companyname="pqr" >pqr</div>

#3


0  

Try this :Use attribute selector like below

试试这个:使用如下的属性选择器。

$(".companyname[data-companyname='abc']").show();

#1


2  

$('div[data-companyname="abc"]').show()
.companyname {
  display: none
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="companyname" data-companyname="abc">1</div>
<div class="companyname" data-companyname="xyz">2</div>
<div class="companyname" data-companyname="pqr">3</div>

use the attr selector

使用attr选择器

#2


1  

You need to use attribute equals selector

您需要使用属性= selector

Selects elements that have the specified attribute with a value exactly equal to a certain value

选择具有指定属性且值完全等于某个值的元素

$(".companyname[data-companyname=abc]").show();

$(".companyname[data-companyname=abc]").show();
.companyname{display:none}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="companyname" data-companyname="abc" >abc</div>
<div class="companyname" data-companyname="xyz" >xyz</div>
<div class="companyname" data-companyname="pqr" >pqr</div>

#3


0  

Try this :Use attribute selector like below

试试这个:使用如下的属性选择器。

$(".companyname[data-companyname='abc']").show();