The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript pass function inside my plugin to $.proxy

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
  • #164722


    I have written plugin for my tabs


    // my jQuery tabs

    (function ($) {

        mySimpleTabs: function (settings) {
            var defaults = {
                tabActiveClass: "active", // class to be added when it is active
                TabContentClass: "tab-content" // class to be used to hide/show respective tab content
            var settings = $.extend(defaults, settings); // override the defaults with custom settings
            return this.each(function () {
                var element = $(this); // element that contains tabs and tab contents
                var tabs = element.find("> ul > li > a");
                var contents = element.find("> ." + settings.TabContentClass);
                function initialize() {
                    //Initialize the tabs to show first tab on page load
                // action on cliking tabs
                $(tabs).click(function (e) {
                function switchtabs(clickedtab) {
                    alert("yo man");
                    if (!$(clickedtab).hasClass("active")) { // if clicked tab is already active, do nothing, else, go inside
                        tabs.removeClass("active"); // remove active class from all tabs
                        $(clickedtab).addClass("active"); // add active class to the clicked tab
                        contents.hide();            // hide all content divs
                        var selected_tab = $(clickedtab).attr("rel"); // get the selected tab ID
                        $(selected_tab).show(); //show respective tab
                        return false; // Cancel the link behavior
                    return false; // Cancel the link behavior in case active tab is clicked


    I want to pass switchtabs() function to $.proxy as below, as i want to switch the tabs on clicking another link like below.

    $(".viewonmap").on("click", $.proxy(switchtabs, $("#viewtabs > ul > li > a[rel=#mapview]")));

    I know switchtabs cannot be called just like that as it inside jquery plugin.

    can anyone please help me on how I can pass this function correctly.

    Thanks in advance..

    PS: I do not have access to Codepen. Apologies for this long post.

Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.