开发者

Get all visible DIVs on a page with javascript?

开发者 https://www.devze.com 2022-12-20 09:55 出处:网络
Another short Q, is there any short piece of code to get all DIVs on a page which have th开发者_运维百科e visibility set to \'block\' or \'inline\'?

Another short Q, is there any short piece of code to get all DIVs on a page which have th开发者_运维百科e visibility set to 'block' or 'inline'?

Thanks


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);
}


Using jQuery:

$("div:visible")

http://api.jquery.com/visible-selector/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号