Select div using wildcard ID

前端 未结 9 1764
旧时难觅i
旧时难觅i 2020-11-29 11:30

How to select a div using it\'s ID but with a widcard?

If the DIV\'s ID is statusMessage_1098, I would like to select it in some way like document

9条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 12:13

    Update for 2020:

    Using jQuery you can do this

    $("div[id^=statusMessage_]")
    

    **Omit the single quotes.

    I also often add a variable to the end:

    $("div[id^=statusMessage_" + id + "]")
    

提交回复
热议问题