Search code examples
triggersonclickhrefsipjquery-click-event

trigger a href sip/tel link on button click jquery


I'm trying to trigger a click event that will open my href sip/tel link when user clicks the button, but it doesn't trigger the click event after the button has been pressed.

jquery code:

$('#next_button').click(function() {
       var num = $(this).val();
       $('#call-num'+num).trigger('click');
       alert(num);
});

href code:

<a href="tel:001(999) 888-3333" id="call-num1">(999) 888-3333</a>
<button id="next_button" value="1">Next</button>

Solution

  • $('#next_button').on('click', function() {
          var num = $(this).val();
          var call = $('#call-num'+num).attr('href');
          location.href = call;
          alert(call);
    });