user3376068
user3376068

Reputation: 11

Taphold returning dynamic content

For the life of me I can't figure out a way of doing this. I'm having content returned from a database through a loop. When the div is held down I detect it with the taphold and display a popup box prompting the user. What I need to do is detect which div has been held so I can return the postID to process. Hopefully this example will clear it up.

<div data-role="popup" id="popupBox">
    I need to be able to process the post ID of the held div here
</div>

<?php
    while($row = $getContent->fetch()) {
        echo "<div class='popup'>";
            echo $row['postID'];
            .....
        echo "</div>";
    }
?>

<script>
    $(function(){
      $( "div.popup" ).on( "taphold", tapholdHandler );

      function tapholdHandler( event ){
        $("#popupBox").popup('open');
      }
    });
</script>

Upvotes: 1

Views: 111

Answers (1)

Tomanow
Tomanow

Reputation: 7377

Try this:

$(function () {
    $("div.popup").on("taphold", function(event) {
        var postId = $(this).text();
        //var postId = parseInt($(this).text());
        $("#popupBox").popup('open');
        var link = $('#popupBox').find('a');
        var url = link.attr('href');
        var newLink = url + '?id=' + postId;
        link.attr('href', newLink);
    });
});

Upvotes: 1

Related Questions