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 7539807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:28:49+00:00 2026-05-30T07:28:49+00:00

How do I get the options from another set of options. JS Fiddle Example

  • 0

How do I get the options from another set of options.

JS Fiddle Example
at the moment this is outputting the name of each option in opt.social. Instead I want it to fetch the actual HTML related to each option name.

Thus the idea is that in the future when a new social media site is built, this can easily be added via the plugin options without the need to edit the plugin.

Example:

$.each(opt.social, function(index, value) {
  html += "<li>" + value.name + "</li>";
});

I have tried

opt[value.name];
opt.value.name;
opt(value.name);

Full example:

(function ($) {

$.fn.socialMedia = function (options) {

    // default configuration properties
    var defaults = {
        social: [
             { name: "facebook.like_large"},
             { name: "twitter.large"},
             { name: "googlePlus.large"}
        ],
        facebook: {
            like_large: '<div class="fb-like" data-href="{url}" data-send="false" data-layout="box_count" data-width="120" data-show-faces="false"></div>',
            like_small: '<div class="fb-like" data-href="{url}" data-send="false" data-layout="button_count" data-width="120" data-show-faces="false" data-colorscheme="dark"></div>',
            share: '<a name="fb_share" type="box_count" share_url="{url}" href="http://www.facebook.com/sharer.php?u={url}&t={title}">Share</a>'
        },
        twitter: {
            large: '<a href="http://twitter.com/share" class="twitter-share-button" data-url="{url}" data-count="vertical">Tweet</a>',
            small: '<a href="http://twitter.com/share" class="twitter-share-button" data-url="{url}">Tweet</a>'
        },
        googlePlus: {
            large: '<div class="g-plusone" data-size="tall" data-href="{url}"></div>',
            small: '<div class="g-plusone" data-size="medium" data-annotation="inline" data-width="120" data-href="{url}"></div>'            
        }
    };

    var opt = jQuery.extend(defaults, options);

    // Generate HTML
    $(this).append(generateHtml());

    function generateHtml() {            
        var html = '<ul>';

        $.each(opt.social, function(index, value) {
            html += "<li>" + value.name + "</li>";
        });

        html += '</ul>';            
        return html;
    }
}

  $("body").socialMedia();  

})(jQuery);
  • 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-05-30T07:28:50+00:00Added an answer on May 30, 2026 at 7:28 am

    In that code, opt.social is an array of objects, each with a “name” property.

    Thus,

    var firstOptName = opt.social[0].name;
    

    And so on. The opt.social array should be indexed numerically. Now, opt.googlePlus is just an object with (in this case) two properties, so there’s no array indexing involved:

    var googleLarge = opt.googlePlus.large;
    

    edit — if you want to just alter that loop to show the HTML:

    $.each(opt.social, function(index, value) {
      var parts = value.name.split('.'), partVal = opts;
      for (var i = 0; i < parts.length; ++i)
        partVal = partVal[parts[i]];
      html += "<li>" + partVal + "</li>";
    });
    

    The trick is that those “name” properties are in the form of dotted “paths” through an object graph, and JavaScript does not have a built-in way of interpreting those. The code I wrote above walks through the object part by part (parts are separated by “.” characters), starting from the outer “opts” object.

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

Sidebar

Related Questions

I am trying to get the selected option from a dropdown and populate another
I have a <select>. Using JavaScript, I need to get a specific <option> from
public class Options { public FolderOption FolderOption { set; get; } public Options() {
Swedish characters get substituted when setting the tabTemplate option. For example using ö in
This relates to another question I asked earlier today. I built SVN 1.6.2 from
I cannot seem to get the value from a select option that has been
With the new caching options in Rails 2.1 i get nice entires in my
Is it possible to get Windows Server 2003 hosted with options similar to Linux
I get the following when I start my Zsh. Usage: prompt <options> Options: -c
Is there any debugging options built-in in the Xlib (libX11.so)? Can I get list

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.