Home > Mobile >  Disable tel: links dynamically content
Disable tel: links dynamically content

Time:10-05

So I'm trying to disable tel: links and this code works fine but not on content that is added dynamically, for example if there is a searchbar on the page that previews the results and it contains tel: numbers, it won't "disable" those links.

 $(function() {
            $('a[href^="tel:"]').on('click', function(e) {
                e.preventDefault();
            });
        })

Tried figure out how to do Delegated events but got stuck. ;(

CodePudding user response:

Try to use like below, it will work for dynamic content:

$(function() {
            $('body').on('click', 'a[href^="tel:"]', function(e) {
                e.preventDefault();
            });
        })
  • Related