2

I'm trying to get all callable phone numbers out of an html-received with a get:

onload: function (data)
{
    data = $.parseHTML(data.response);
    var content = $.trim($(data).find('[href^=callto:]').text());
    console.log(content)
    //var content= $(data).find('.');
}

The data is correct, i successfully found find('.tel'), a class used in the html.

exexzian
  • 7,782
  • 6
  • 41
  • 52
Himmators
  • 14,278
  • 36
  • 132
  • 223
  • Probably your links are at the top level of the `$.parseHTML` result array. Use `filter` instead of `find`. (If this is your problem, here's a very closely related question: [jQuery() not finding elements inside of results from jQuery.parseHTML()](http://stackoverflow.com/questions/15403600/jquery-not-finding-elements-inside-of-results-from-jquery-parsehtml).) – apsillers Jul 30 '13 at 17:10

3 Answers3

8

$('a[href^="tel:"]') will give you all anchors with a tel: scheme.

Using your sample code: data.find('a[href^="tel:"]')

André Dion
  • 21,269
  • 7
  • 56
  • 60
1

This is how I managed to resolve this problem on my end. :)

/* All phone numbers to href */
var regex = /\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/;
$('tr td:nth-child(3)').each(function() {
    var text = $(this).html();
    text = text.replace(regex, "<a href=\"tel:$&\">$&</a>");
    $(this).html(text);
});
0

The colon is a special character in jQuery selectors. You should escape it like this: $(data).find('[href^=callto\\:]')

Petko Bossakov
  • 510
  • 2
  • 10