Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

jquery - Get all visible DIVs on a page with javascript?

Another short Q, is there any short piece of code to get all DIVs on a page which have the visibility set to 'block' or 'inline'?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

1 Answer

0 votes
by (71.8m points)

It's easy with jQuery...

$("div:visible")

But if you want to be old school...

var divs = document.getElementsByTagName("DIV");
var elems = [];

for(var i = 0; i < divs.length; i++) {
  var div = divs[i];
  var vis = div.style.visibility;

  if(vis == 'block' || vis == 'inline')
    elems.push(div);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
...