astwood astwood - 3 years ago 112
jQuery Question

Phonegap 2.9.0 developing in Xcode: Error: TypeError: 'undefined' is not a function in file

I keeping getting a debug error code outputting to the Xcode console when I try and click on the row in question and kick off the event listener.

Error Message in full (long file path removed to keep it clean):

Error: TypeError: 'undefined' is not a function in file:///Users/....../index.js at line 1339

1339 is first line of code block displayed.


$("#contact-list").on("click", "a", function(event){
var me = this;
console.log('The event listener is working');

var phoneNumber = me.attr('id').text();
console.log('phoneNumber is being sent');
if (phoneNumber.substr(0, 1) == '+') {
phoneNumber = me.userExitCode + phoneNumber.substr(1);
phoneNumber = phoneNumber.replace(/[^0-9]/g, '');

var data = {
'name': me.children('h3').val(),
'phone_number': phoneNumber,
'part': 'contact'

Answer Source
var phoneNumber = me.attr('id').text();

Will not work. If your intentions were to grab the id of me element,

var phoneNumber = $(me).attr('id');
  1. I wrapped your me with $ (because me is this, jQuery expects $(this)
  2. I removed text() function call, because attr itself will return text.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download