Grab button click on several lines

2

I need to get all the clicks of a generated html in a select.

I have the following structure:

<tr class="pesquisar" data-idlocalidade="<?php echo $linha['IDLocalidade']; ?>">
    <td class="NomeLocalidade"><?php echo $linha['NomeLocalidade']; ?></td>
    <td class="TelComercial1"><?php echo $linha['TelComercial1']; ?></td>
    <td class="Endereço"><?php echo $linha['EndLogradouro'].' - '.$linha['EndBairro']; ?></td>
    <td class="EndCidade"><?php echo $linha['EndCidade']; ?></td>
    <td class="acoes-linha">
        <div class="btn-group btn-group btn-group-justified">
            <?php if (in_array("REGRA_ADMIN_PERFIL_EMPRESAS", $_SESSION['Autoridades'])) { ?> <a href="javascript:;" class="btn btn-xs default tooltips DefinirSede <?php echo (($linha['IDLocalidade']==$EmpresaInfo->_IDSede)?'disabled':''); ?>" data-container="body" data-placement="top" data-original-title="Defninir como Localidade Sede"><i class="fa fa-map-marker"></i> </a> <?php }; ?>
            <!-- Aqui faria o envio para a pagina de edição--> <?php if (in_array("REGRA_ADMIN_PERFIL_EMPRESAS", $_SESSION['Autoridades'])) { ?> <a  class="btn btn-xs default tooltips Editar" id="EditarLocalidade" data-container="body" data-placement="top" data-original-title="Editar"><i class="fa fa-pencil-square-o"></i> </a> <?php }; ?>
        </div>
    </td>
</tr>

It returns me a normal html.

When I want to get the click of a third, fourth line, it does not identify.

$("#EditarLocalidade").click(function(){
    alert("ooi");
})

The alert only appears in the first field, when it would have to appear in all.

Only the arrow function works.

    
asked by anonymous 20.01.2017 / 18:17

1 answer

2

The id attribute must be unique in the form, it should never be repeated. You will have to obtain it through another selector, such as a class or any attribute:

  $("a[data-original-title='Editar']").click(function(){
      alert("ooi");
  })
    
20.01.2017 / 18:23