trigger button click

About Forums Forum trigger button click

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #596
    lunchbox
    Participant

    hi there,

    I’m looking at how to click an html button using button connected to arduino. I know it sounds silly, but couldn’t get it to work. I modified the getting started example like this:

    function onButtonRelease(event) {
    // get a reference to the button object that fired the event
    var btn = event.target;
    $(‘#button’).html(“button: pin = ” + btn.pinNumber + ” released”);
    $(‘button’).trigger(‘click’);
    }

    where on the html i have the button tag

    It didn’t work. Anybody has solution for this? Cheers 🙂

    • This topic was modified 8 years, 6 months ago by lunchbox. Reason: markup didn't appear
    • This topic was modified 8 years, 6 months ago by lunchbox.
    • This topic was modified 8 years, 6 months ago by lunchbox.
    #600

    In order for the jQuery trigger() method to work, you need to create a click handler somewhere in your code. So you need both:

    // put this at the end of the onReady() method
    $(‘button’).on(‘click’, handleClick);

    // now trigger should work in the onButtonPress or onButtonRelease methods
    $(‘button’).trigger(‘click’);

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Forum’ is closed to new topics and replies.