How can I select an element with multiple classes in jQuery?

前端 未结 13 2660
一向
一向 2020-11-22 00:51

I want to select all the elements that have the two classes a and b.


So, only the e

13条回答
  •  野性不改
    2020-11-22 01:10

    You can use getElementsByClassName() method for what you want.

    var elems = document.getElementsByClassName("a b c");
    elems[0].style.color = "green";
    console.log(elems[0]);
    • a
    • a, b
    • a, b, c

    This is the fastest solution also. you can see a benchmark about that here.

提交回复
热议问题