CSS / Javascript Show / Hide DIV using a CSS class?

前端 未结 7 1814
陌清茗
陌清茗 2020-12-20 17:14

I\'ve googled around and found many scripts for hiding and showing DIV contents, as a toggle on button click.

But they are work using ID\'s.

I would like to

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-20 17:47

    Using jQuery Selectors, you can find an ID by:

    $("#id")
    

    Changing that to select classes is trivial:

    $(".className")
    

    Without using jQuery its a little more non-trivial, but you can check this SO question for some help:

    How to getElementByClass instead of GetElementById with Javascript?

提交回复
热议问题