JQuery, how to find list of div's with similar ID

后端 未结 4 725
情话喂你
情话喂你 2021-01-30 16:30

I have a structure of html like this:

some elements inside
some elements inside
相关标签:
4条回答
  • 2021-01-30 16:40

    you can actually use a regular expression in a selector to achieve exactly what you are looking for, as such:

    $("div:regex(id, yourRegularExpression)");
    

    (Note: this does require the regex-selector plugin)

    Someone asked a similar question here.

    You can read all about regular expressions here.

    As others have pointed out, you can achieve the same result like this:

    $("div[id^='partOfID']");
    

    by using a simple jQuery selector. For more complex selections, though, you will need to use the regex plugin or do it manually, as noted in the linked question.

    good luck!

    0 讨论(0)
  • 2021-01-30 16:47
    var trigerList = $("div[id^='triger']");
    
    0 讨论(0)
  • 2021-01-30 16:54

    Select all div elements whose id attribute contains the string triger:

    $('div[id*="triger"]');
    

    There's more about using *= in the jQuery documentation: Attribute Contains Selector [name*="value"]

    0 讨论(0)
  • 2021-01-30 16:55

    You can use the following:

    $("div[id^='triger']")
    

    This will return all <div> with id starting (^=) with triger.

    You can get more information about the various jQuery selectors in the jQuery docs:

    API/Selectors

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