jQuery ID starts with

前端 未结 2 1392
醉话见心
醉话见心 2020-11-28 05:09

I am trying to get all elements with an id starting with some value. Below is my jQuery code. I am trying to use a JavaScript variable when searching for items. But it does

2条回答
  •  清歌不尽
    2020-11-28 06:03

    Here you go:

    $('td[id^="' + value +'"]')
    

    so if the value is for instance 'foo', then the selector will be 'td[id^="foo"]'.

    Note that the quotes are mandatory: [id^="...."].

    Source: http://api.jquery.com/attribute-starts-with-selector/

提交回复
热议问题