Home › Forums › JavaScript › pass function inside my plugin to $.proxy
- This topic is empty.
Viewing 1 post (of 1 total)
-
AuthorPosts
-
March 4, 2014 at 11:38 pm #164722sadunareshParticipant
Hi,
I have written plugin for my tabs
`
// my jQuery tabs
(function ($) {
jQuery.fn.extend({ 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); initialize(); function initialize() { //Initialize the tabs to show first tab on page load tabs.eq(0).addClass("active"); contents.hide(); contents.eq(0).show(); }; // action on cliking tabs $(tabs).click(function (e) { e.preventDefault(); switchtabs(this); }); 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 } }); } });
})(jQuery);`
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.
-
AuthorPosts
Viewing 1 post (of 1 total)
- The forum ‘JavaScript’ is closed to new topics and replies.