Element or class LIKE selector for jQuery?

前端 未结 3 1136
臣服心动
臣服心动 2020-12-02 06:35

For whatever reason I have these classes called .main_sub1, .main_sub2 etc. Never mind why I can\'t have .main .sub.

Is there

3条回答
  •  青春惊慌失措
    2020-12-02 07:15

    Yes, you can use an attribute selector to match certain values for the class attribute.

    $('[class^=main]') // class begins with "main"
    $('[class*=main]') // class contains "main" anywhere within it
    

提交回复
热议问题