-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
  • 704,970
  • 168
  • 1,303
  • 1,425
S. M. Shahinul Islam
  • 2,730
  • 3
  • 35
  • 67

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
  • 110,383
  • 23
  • 155
  • 178