About getElementById find multiple ids name?
I have an id tag
<div id="view_1"></div>
<div id="view_2"></div>
<div id="view_3"></div>
I am using getElementsByClassName how can it work
but "class" I take it to delimit the css style
How can document.getElementById find -> "view_1" "view_2" "view_3"
function hideDIV(){
var divs = document.getElementById('view'.*);
for(var i=0; i<divs.length; i++) {
divs[i].style.display='none';
}
}
+3
source to share
5 answers
document.querySelectorAll('div[id^="view_"]');
$('div[id^="view_"]');
div[id^="view_"] { ... }
But consider using classes, rather than identifiers, for semantically targeted elements.
For example: find all DIVs with class targetDiv
and add class to them hidden
. Then define the class hidden
as display: none
in CSS.
0
source to share