Problem with JS converting module form d6 to d7 I am converting a module from d6 version to d7 and I encountered some javascript problems.In the following code below .each() function isnt getting fired.But the its going till the .attachVote function for sure. Is this correct way to do it, or am I missing something?????

(function ($) {
/**
 * Create the smackdown object/namespace.
 */
Drupal.smackdown = function() {};

/**
 * Attach the smackdown behavior to nodereferences on the page.
 *
 * @param context
 *   The jQuery object to apply the behaviors to.
 */
Drupal.behaviors.smackdown = {
 attach: function(context, settings) {
    if (typeof Drupal.settings.smackdown !== 'undefined') {
        var field_1 = '.field-' +        Drupal.settings.smackdown.field1.name.replace(/_/g, '-');
         var field_2 = '.field-' +  Drupal.settings.smackdown.field2.name.replace(/_/g, '-');
         if (Drupal.settings.smackdownPerm == 1) {
             Drupal.smackdown.attachVote(context, field_1 + ' .field-item a');
             $(field_1 + ' .field-item a').attr('rel', Drupal.settings.smackdown.field1.nid).addClass('smackdown-processed');
            Drupal.smackdown.attachVote(context, field_2 + ' .field-item a');
            $(field_2 + ' .field-item a').attr('rel', Drupal.settings.smackdown.field2.nid).addClass('smackdown-processed');
        }
    else {
         Drupal.smackdown.attachNotice(context, field_1 + ' .field-item a');
         Drupal.smackdown.attachNotice(context, field_2 + ' .field-item a');
     }
   }
 }
};

/**
 * Attach the smackdown behavior to a particular link.
 *
 * @param context
 * @param selector
 *   jQuery selector for links to attach behavior to.
 */
Drupal.smackdown.attachVote = function(context, selector) {
 $(selector, context).each(function() {
     var $element = $(this);
     // Attach the on-click popup behavior to the element.
     $element.click(function(e){
     Drupal.theme('voting', $element);
     var nid = $element.attr('rel'); // not compatible with clean urls
     var sid = Drupal.settings.smackdown.sid;
     var params = {'cid':nid, 'sid':sid};
     // post nid and context to smackdown/vote
     ajaxOptions = {
       url: Drupal.settings.basePath + 'smackdown/vote/' +  Drupal.settings.smackdown.token,
      dataType: 'json',
      data: params,
      success: function(json) {
        // we put the location into a variable so that it can be changed by other modules
        location.href = json.location
      }
    };
    $.ajax(ajaxOptions);
    return false;
  });
});
};

Drupal.smackdown.attachNotice = function(context, selector) {
 $(selector, context).each(function() {
   var $element = $(this);
   $element.click(function(e) {
    Drupal.theme('notice', $element);
    return false;
   });
 });
};

Drupal.theme.prototype.voting = function(element) {
  var output = "&lt;div id='voting-indicator'&gt;" + Drupal.t('Voting...') + "  &lt;/div&gt;";
 element.parent().css({'background-color':'#ffc'});
 return element.parent().append(output);
   };

Drupal.theme.prototype.notice = function(element) {
  var output = "&lt;div id='voting-indicator'&gt;" + Drupal.t('You do not have  sufficient rights to vote.') + "&lt;/div&gt;";
 element.parent().css({'background-color':'#ffc'});
 return element.parent().append(output);
 };
})(jQuery);
Make sure that the $(selector, context) is valid on the page it's being called. You should be able to do this by doing a console.log($(selector, context)); in the first line of the function.

Assuming the selector and context are valid, the .each() should be executed.

If they are not valid, you may have to replace the element or context being passed into Drupal.smackdown.attachNotice().