Reputation: 2293
How can i get the the blocked div id in jquery
HTML
<div id="USDC1" style="" class="tablegraphview">USDC2</div>
<div id="USDC2" style="display:none" class="tablegraphview">USDC2</div>
<div id="USDC3" style="display:none" class="tablegraphview">USDC3</div>
Javascript
function tablegraphview(){
var getid = $('.tablegraphview').attr('id');
alert(getid);
}
for ex
<div id="USDC2" style="display:block" class="tablegraphview">USDC2</div>
I need to current div id how can i do that in jquery
Upvotes: 0
Views: 4110
Reputation: 2655
Try with $(this).is(':visible')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="USDC1" style="" class="tablegraphview">USDC2</div>
<div id="USDC2" style="display:none" class="tablegraphview">USDC2</div>
<div id="USDC3" style="display:none" class="tablegraphview">USDC3</div>
<script>
$(function() {
$(".tablegraphview").each( function(){
if($(this).is(':visible')){
alert($(this).attr("id"));
}
});
});
</script>
Or
As per @pieter command
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="USDC1" style="" class="tablegraphview">USDC2</div>
<div id="USDC2" style="display:none" class="tablegraphview">USDC2</div>
<div id="USDC3" style="display:none" class="tablegraphview">USDC3</div>
<script>
$(function() {
alert($(".tablegraphview:visible").attr('id'));
});
</script>
Upvotes: 3