Skip to main content
added 119 characters in body
Source Link
Jeff
  • 347
  • 1
  • 4
  • 13

I have this HTML:

    <div class="ac-users ac-appender">
        <div class="chip" data-id="3069243" data-text="">IBM(3069243)
            <i class="material-icons close">close</i>
        </div>
        <div class="chip" data-id="6640418" data-text="">INTC(6640418)
            <i class="material-icons close">close</i>
        </div>
        <div class="chip" data-id="1452690" data-text="">RJF(1452690)
            <i class="material-icons close">close</i>
        </div>
    </div>

I need to select from this and get an array of the data-id. $('.chip') selects the array of chips effectively, but I am not able to extract the values of data-id(s)

With jquery I am using the following but it only brings back the first item:

    $('.chip').attr("data-id");

I have this HTML:

    <div class="ac-users ac-appender">
        <div class="chip" data-id="3069243" data-text="">IBM(3069243)
            <i class="material-icons close">close</i>
        </div>
        <div class="chip" data-id="6640418" data-text="">INTC(6640418)
            <i class="material-icons close">close</i>
        </div>
        <div class="chip" data-id="1452690" data-text="">RJF(1452690)
            <i class="material-icons close">close</i>
        </div>
    </div>

I need to select from this and get an array of the data-id. $('.chip') selects the array of chips effectively, but I am not able to extract the values of data-id(s)

I have this HTML:

    <div class="ac-users ac-appender">
        <div class="chip" data-id="3069243" data-text="">IBM(3069243)
            <i class="material-icons close">close</i>
        </div>
        <div class="chip" data-id="6640418" data-text="">INTC(6640418)
            <i class="material-icons close">close</i>
        </div>
        <div class="chip" data-id="1452690" data-text="">RJF(1452690)
            <i class="material-icons close">close</i>
        </div>
    </div>

I need to select from this and get an array of the data-id. $('.chip') selects the array of chips effectively, but I am not able to extract the values of data-id(s)

With jquery I am using the following but it only brings back the first item:

    $('.chip').attr("data-id");
Source Link
Jeff
  • 347
  • 1
  • 4
  • 13

Can't select data attribute from html

I have this HTML:

    <div class="ac-users ac-appender">
        <div class="chip" data-id="3069243" data-text="">IBM(3069243)
            <i class="material-icons close">close</i>
        </div>
        <div class="chip" data-id="6640418" data-text="">INTC(6640418)
            <i class="material-icons close">close</i>
        </div>
        <div class="chip" data-id="1452690" data-text="">RJF(1452690)
            <i class="material-icons close">close</i>
        </div>
    </div>

I need to select from this and get an array of the data-id. $('.chip') selects the array of chips effectively, but I am not able to extract the values of data-id(s)