SHERIN AS SHERIN AS - 2 months ago 5
jQuery Question

How to show particular div using jQuery



<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



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





How to get this?

Answer

$('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

Comments