Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9223453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:05:07+00:00 2026-06-18T04:05:07+00:00

Most the code works except it is not grabbing each a that I need

  • 0

Most the code works except it is not grabbing each a that I need for each individual .post

(function ($) {
'use strict';
var url = window.location.href.split('#')[0];
var post = $('.post').children('a[name]').attr('name');
var helpers = {
        "defaults": {
            "post": post,
            "href": url+'#',
            "send": 'true',
            "layout": 'button_count',
            "width": '125',
            "faces": 'false',
            "font": 'verdana',
            "action": 'like',
            "scheme": 'light',
        },
        "init": function (options) {

            var settings = $.extend({}, helpers.defaults, options),

                easyface = $('<div />').addClass('easyface fb-like').attr({
                    "data-href": settings.href + settings.post,
                    "data-send": settings.send,
                    "data-layout": settings.layout,
                    "data-width": settings.width,
                    "data-show-faces": settings.faces,
                    "data-font": settings.font,
                    "data-action": settings.action,
                    "data-colorscheme": settings.scheme
                });

            return this.each(function (i, elem) {
                var self = $(elem),                 
                    data = self.data('easyface');  
                if (!data) {   

                    self.data('easyface', easyface);
                    self.append(easyface);
                }
            });
        },
        "destroy": function () {
            return this.each(function (i, elem) {
                var self = $(this),                
                    data = self.data('easyface');   // test to see if we've already called init on this element

                $(window).unbind('.easyface');      // unbind any namespaced events, assuming you've namespaced them like "click.easyface"
                self.removeData('easyface');        // remove the data flag
                self.find('.easyface').remove();    // remove the appended div
            });
        }

    };
//define the method "easyface"
$.fn.easyface = function (method) {
    if (helpers[method]) {
        // call the method and pass in the settings
        return helpers[method].apply(this, Array.prototype.slice.call(arguments, 1));
    } else if (typeof method === 'object' || !method) {
        // default to the init method and pass in the arg
        return helpers.init.apply(this, arguments);
    } else {
        // throw an error
        $.error('Method ' + method + ' does not exist on jQuery.tooltip');
    }
};
}(jQuery));
 $(function() {
   $('body').append('<div id="fb-root"></div>');
   (function(d, s, id) {
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) return;
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=477049588983712";
     fjs.parentNode.insertBefore(js, fjs);
     }(document, 'script', 'facebook-jssdk'));
   });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:05:09+00:00Added an answer on June 18, 2026 at 4:05 am

    A few pointers on what you’ve tried, notably with your pattern of:

    $(this).attr('data-send', function () {
        return + send;
    });
    $(this).attr('data-layout', function () {
        return + layout;
    });
    $(this).attr('data-width', function () {
        return + width;
    });
    

    which I can best explain with comments:

    // in your execution scope, "this" is the window object
    $(this).attr('data-href', function () {
        // "href" is not in any scope of the IIFE
        // and is therefore either a global variable
        // or is undefined. Also the plus sign, when
        // used like this, will try to convert your
        // "href" to a number which is likely to return
        // NaN given that "href" is likely to be undefined
        // or a non-numeric string
        return + href;
    });
    

    That said, here’s how I would structure your plug-in with comments as to why I would structure it so:

    // Start with an IIFE and pass in either jQuery, or jQuery.noConflict
    // which will map it to the dollar sign so that the the dollar sign
    // cannot be overwritten by another library in the scope of its execution.
    (function ($) {
        'use strict';
        // contain all methods and settings in a local variable.
        // this helps ensure clean namespacing and
        // preserves scope
        var helpers = {
                "defaults": {
                    "post": "",                 //pass the post id in as a parameter
                    "href": '/',
                    "send": 'true',
                    "layout": 'button_count',
                    "width": '125',
                    "faces": 'false',
                    "font": 'verdana',
                    "like": 'like'
                },
                "init": function (options) {
                    // combine passed in options with the defaults in a new object
                    var settings = $.extend({}, helpers.defaults, options),
                        // build the easyface element to attach
                        easyface = $('<div />').addClass('easyface fb-like').attr({
                            "data-href": settings.href + settings.post, // concatenate with your href here.
                            "data-send": settings.send,
                            "data-layout": settings.layout,
                            "data-width": settings.width,
                            "data-show-faces": settings.faces,
                            "data-font": settings.font,
                            "data-like": settings.like
                        });
                    // return this.each to preserve chainability
                    return this.each(function (i, elem) {
                        var self = $(elem),                 // cached reference to the element
                            data = self.data('easyface');   // test to see if we've already called init on this element
                        if (!data) {    // If the plugin hasn't been initialized yet
                            //Do more setup stuff here
                            self.data('easyface', easyface);
                            self.append(easyface);
                        }
                    });
                },
                "destroy": function () {
                    return this.each(function (i, elem) {
                        var self = $(this),                 // cached reference to the element
                            data = self.data('easyface');   // test to see if we've already called init on this element
                        // namespacing for the win
                        $(window).unbind('.easyface');      // unbind any namespaced events, assuming you've namespaced them like "click.easyface"
                        self.removeData('easyface');        // remove the data flag
                        self.find('.easyface').remove();    // remove the appended div
                    });
                }
                /*
                 * other example methods
                 *
                 *  "reposition": function () {},
                 *  "show": function () {},
                 *  "hide": function () {},
                 *  "update": function (content) {}
                 */
            };
        //define the method "easyface"
        $.fn.easyface = function (method) {
            if (helpers[method]) {
                // if the arg passed was a string that indicates a method above
                // call the method and pass in the settings
                return helpers[method].apply(this, Array.prototype.slice.call(arguments, 1));
            } else if (typeof method === 'object' || !method) {
                // if the arg passed was an object, or no arg was passed
                // default to the init method and pass in the arg
                return helpers.init.apply(this, arguments);
            } else {
                // don't know what to do with this
                // throw an error
                $.error('Method ' + method + ' does not exist on jQuery.tooltip');
            }
        };
    }(jQuery));
    

    In your example fiddle, you can pass the post id in as an option like this:

    $('.postfoot').easyface({
        "post": $('.post').children('a[name]').attr('name')
    });
    

    Here’s an updated fiddle to demonstrate: http://jsfiddle.net/zUeFL/9/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following snippet of code works most of the time, except in certain windows.
I'm creating a responsive layout that works great on most formats, except smartphones with
The following code works fine in most browsers but it won't work in Internet
I have a jQuery select which works in most browsers axcept IE. The code
I will keep this quick. The attached code for the most part works i
I use astyle to format my code most of the time, and I love
I am trying to use SpinLock, but even this most basic code in a
I'm using Mongoid::Versioning which works great except that I would like to prevent several
EDIT : I just found something that works on every page load except the
The snippet of the PHP script below works for the most part... except for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.