AlexW
AlexW

Reputation: 2589

Jquery Mobile - swipe left get row id

Im using Query mobile to swipe left which works and brings me up an alert window that states, you swiped. but I get no id in the alert.

    $(function(){
    // Bind the swipeleftHandler callback function to the swipe event on div.box
    $(".row").on( "swipeleft", swipeleftHandler );
    // Callback function references the event target and adds the 'swipeleft' class to it
    function swipeleftHandler( e ){
        $id =  e.target.id;
        alert( 'You swiped ' + $id  );
    }
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-mobile/1.4.5/jquery.mobile.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-mobile/1.4.5/jquery.mobile.min.css" rel="stylesheet"/>

<table class="alert-table" cellspacing="0" cellpadding="0">         
    <tr>
        <th>Date/Time</th>               
        <th>Alert</th>
        <th>Acknowledged By</th>
        <th>&nbsp;</th>
    </tr>   
    <tr id="12345" class="row {% cycle 'tr-1' 'tr-2' %}">
        <td>01/01/2017 3:41</td>
        <td>
            Device: Server <br/>
            Component: CPU <br />             
            Alert: 100%
        </td>
        <td>Bill Jones</td>
        <td></td>

    </tr>
    <tr id="12346" class="row {% cycle 'tr-1' 'tr-2' %}">
        <td>01/01/2017 4:41</td>
        <td>
            Device: Switch 02<br/>
            Component: Port 10 <br />             
            Alert: Down
        </td>
        <td>Fred Smith</td>
        <td></td>

    </tr>
</table>

Upvotes: 0

Views: 478

Answers (1)

Makarand Patil
Makarand Patil

Reputation: 1001

try $id = $(this).attr('id'); instead of $id = e.target.id;. it should work

Upvotes: 2

Related Questions