My HTML
<div id="a">Showcode</div>
<div id="b">Code 1</div> // b1
<div id="b">Code 2</div> // b2
My code:
$(document).ready(function(){
$('#b').hide();
})
I am trying to hide all of the id="b" divs at once.
When I run my code I see div id = b (b1) hide but div id = b (b2) does not.
You can't use many same id
<div id="a">Showcode</div>
<div id="b">Code 1</div> // b1
<div id="c">Code 2</div> // b2
You can use class instead
<div clas="a">Showcode</div>
<div clas="a">Code 1</div> // b1
<div clas="a">Code 2</div> // b2
In Jquery
$(document).ready(function(){
$('.a').hide();
});
HTML element IDs must be unique. Use a class name instead, which doesn't have to be unique.
$('.b').hide();
If for some reason you can't change the HTML, then you can use this, which works for duplicate IDs:
$('*[id="b"]').hide();