-1

This is my code

$("#default-hidden").each(function(){
                    $(this).css("display", "none")
                });

its working on only the first occurrence of id=default-hidden, but it should be working on all. What am I doing wrong? TIA.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
S. M. Shahinul Islam
  • 2,780
  • 4
  • 36
  • 68

1 Answers1

1

Because id should be unique, you need to use class instead otherwise only first element get selected. Update id="default-hidden" to class="default-hidden"

$(".default-hidden").each(function(){
//-^-- class selector
    $(this).css("display", "none")
});

In your case there is no need for each() you can just use

$(".default-hidden").css("display", "none")

or you can hide them using hide()

$(".default-hidden").hide()
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188