Corn Hole LI
Corn Hole LI

Reputation: 63

How can I get the "id" of the current visible div

I have tried

var currentVis = $("div:visible");
alert(currentVis);

If the div in question is like: <div id="DIVONE"> I want var currentVis to alert DIVONE. All I get is object object.

Upvotes: 0

Views: 771

Answers (4)

Manian Rezaee
Manian Rezaee

Reputation: 1012

$("div:visible").each(function(){
if($(this).attr("id")=="DIVONE"){
    //do somethings
}});

Upvotes: 0

moonwave99
moonwave99

Reputation: 22817

If your selector finds a div, just refer to its id via:

currentVis[0].id

Upvotes: 1

user1716672
user1716672

Reputation: 1073

var currentVis = $("div:visible");
var id = currentVis.attr('id');

Upvotes: 1

Derek 朕會功夫
Derek 朕會功夫

Reputation: 94309

var currentVis = $("div:visible");
alert(currentVis[0].id);

 -or-

alert(currentVis.attr("id"));

Upvotes: 3

Related Questions