jQuery hide all elements with the same id

前端 未结 3 1296
忘掉有多难
忘掉有多难 2021-01-04 00:35

by topic I have some divs with id = \"loader\".

In my jQuery code I have

  $(\"#loader\").hide(),

but it works only with the first

3条回答
  •  天命终不由人
    2021-01-04 01:15

    Having more than one element with the same ID is not valid HTML. You can only have one element with the ID (#loader) in the whole page. That's why jQuery is hiding only the first element. Use the class instead of the id:

    $('.loader').hide();
    

提交回复
热议问题