Get all visible DIVs on a page with javascript?

Another short Q, is there any short code snippet to get all the DIVs on a page that has visibility set to " block " or " inline "?

thanks

+4
source share
2 answers

Easy with jQuery ...

 $("div:visible") 

But if you want to be an 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); } 
+6
source

Using jQuery:

 $("div:visible") 

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

0
source

Source: https://habr.com/ru/post/1301733/


All Articles