jQuery ID starts with

前端 未结 2 1374
醉话见心
醉话见心 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 05:46

    try:

    $("td[id^=" + value + "]")
    
    0 讨论(0)
  • 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/

    0 讨论(0)
提交回复
热议问题