Search code examples
javascriptandroidjquerycordovaphonegap

Get unique data about clicked button in Phonegap


I have my simple Phonegap app, which is based on tabbed layout. On one of these tabs I have list of tags (more than one). All of these have buttons to edit and delete. Its like this:

        <div class="tag-buttons" uid="TAG_ID">
            <button class="edit-tag btn btn-default btn-sm">Edit</button>
            <button id="aaa" class="remove-tag btn btn-danger btn-sm" onclick="removeTag()">Remove</button>
        </div>

Now I want do handle this removeTag() function. So I have in my JS file this function:

function removeTag()
{
    //controller.removeTag($(this).parent().attr("uid"));
    console.log($(this));
}

Console.log and commented line are only samples. I want to know which button was clicked (I need uid value). All of buttons have this same class. $(this) is returning Window object. Any ideas?


Solution

  • I had made stupid error. Now everything is working. I had to change onclick="removeTag()" to onclick="removeTag(this)" and then in JS function was quite good. I changed function declaration to use additional argument like this:

    function removeTag(button)
    {
        var id = $(button).parent().parent().attr("uid");
        controller.popTag(id);
    }