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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:11:58+00:00 2026-05-19T17:11:58+00:00

I have a function which creates HTML elements out of a select box in

  • 0

I have a function which creates HTML elements out of a select box in order to allow styling. Here’s the code:

$.fn.jqTransSelect = function () {
    return this.each(function (index) {
        var $select = $(this);
        if ($select.hasClass('jqTransformHidden')) {
            return;
        }
        if ($select.attr('multiple')) {
            return;
        }
        var oLabel = jqTransformGetLabel($select);
        var $wrapper = $select.addClass('jqTransformHidden').wrap('<div class="jqTransformSelectWrapper"></div>').parent().css({
            zIndex: 10 - index
        });
        $wrapper.prepend('<div><span></span><a href="#" class="jqTransformSelectOpen"></a></div><ul></ul>');
        var $ul = $('ul', $wrapper).css('width', $select.width() + 10).hide();
        $('option', this).each(function (i) {
            var oLi = $('<li><a href="#" index="' + i + '">' + $(this).html() + '</a></li>');
            $ul.append(oLi);
        });
        $ul.find('a').click(function () {
            $('a.selected', $wrapper).removeClass('selected');
            $(this).addClass('selected');
            if ($select[0].selectedIndex != $(this).attr('index') && $select[0].onchange) {
                $select[0].selectedIndex = $(this).attr('index');
                $select[0].onchange();
            }
            $select[0].selectedIndex = $(this).attr('index');
            $('span:eq(0)', $wrapper).html($(this).html());
            $ul.hide();
            return false;
        });
        $('a:eq(' + this.selectedIndex + ')', $ul).click();
        $('span:first', $wrapper).click(function () {
            $("a.jqTransformSelectOpen", $wrapper).trigger('click');
        });
        oLabel && oLabel.click(function () {
            $("a.jqTransformSelectOpen", $wrapper).trigger('click');
        });
        this.oLabel = oLabel;
        var oLinkOpen = $('a.jqTransformSelectOpen', $wrapper).click(function () {
            if ($ul.css('display') == 'none') {
                jqTransformHideSelect();
            }
            if ($select.attr('disabled')) {
                return false;
            }
            $ul.slideToggle('fast', function () {
                var offSet = ($('a.selected', $ul).offset().top - $ul.offset().top);
                $ul.animate({
                    scrollTop: offSet
                });
            });
            return false;
        });
        var iSelectWidth = $select.outerWidth() + 15;
        var oSpan = $('span:first', $wrapper);
        var newWidth = (iSelectWidth > oSpan.innerWidth()) ? iSelectWidth + oLinkOpen.outerWidth() : $wrapper.width();
        $wrapper.css('width', newWidth);
        $ul.css('width', newWidth - 7);
        oSpan.css({
            width: iSelectWidth
        });
        $ul.css({
            display: 'block',
            visibility: 'hidden'
        });
        var iSelectHeight = ($('li', $ul).length) * ($('li:first', $ul).height());
        (iSelectHeight < $ul.height()) && $ul.css({
            height: iSelectHeight,
            'overflow': 'hidden'
        });
        $ul.css({
            display: 'none',
            visibility: 'visible'
        });
    });
};

What I’m wanting to do is take the ID’s of the original select boxes before they are hidden, and add them ass classes to the newly created $wrapper – how would I do this?

Thanks,
Chris

  • 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-19T17:11:59+00:00Added an answer on May 19, 2026 at 5:11 pm

    After:

        var $wrapper = $select.addClass('jqTransformHidden').wrap('<div class="jqTransformSelectWrapper"></div>').parent().css({
            zIndex: 10 - index
        });
    

    Put:

        $wrapper.addClass($select.attr('id'));
    

    Here is an example.

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

Sidebar

Related Questions

I have a function which wanders through the elements in a page and adjusts
I have a controller action which renders a partial view: public ActionResult Details(int id)
This was interesting. In a select dropdown, trying not to use jQuery (with the
I am absolutely new to the Android platform and have been building an application
I have been working on this for 1 hour with no such luck. Any
I currently have a site that uses the JQuery cycle plugin. The site uses
I have a webpage from the Fogbugz bug tracking system, and using a plugin
I'm currently creating a very small form on my homepage using HTML and JavaScript.
I am running Aprelium Abyss Web Server from my home computer and I have
I'll get straight to the point, I am using jQuery to clone a div

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.