Search code examples
jquerymaterialize

How pass data-id to modal materialize?


I am using api Materialize, i have created a modal for when i clicked a element, this element open a modal asking if i am sure of delete this element. my question is how pass the id of the element to modal? this is mi code:

<div id="modal1" class="modal">
    <div class="modal-content">
        <h4>Eliminar Compra</h4>
        <div class="divider"></div>
        <p>¿Está seguro de que desea eliminar esta compra?</p>
    </div>
    <div class="modal-footer">
        <a href="#!" class="btn modal-action waves-effect waves-red waves-light red">Si, estoy seguro</a>
        <a href="#!" class=" modal-action modal-close waves-effect btn-flat">No</a>
    </div>
</div>
Some code...
<a class="black-text waves-effect menu waves-light confirm" href="#modal1">
    <i class="material-icons">delete</i>
</a>

Solution

  • just set the attributes data-toggle="modal" data-target="#modal1"in a tag and remove href attribute