Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change the Tabs that are created by widget in jquery Mobile by pressing the button?
    primarykey
    data
    text
    <p>I have created the widget in Jquery mobile for Tabs. I want that when i press the button the 2nd Tab should be get selected.Tabs work perfectly Fine i just want it to change the Tab by pressing button. So i want a Jquery function. Here is the Tab widget code.</p> <p>Check out Problem that i am facing Link <a href="http://jsfiddle.net/4j7JV/12/" rel="nofollow">Sample code here for this query</a></p> <pre><code>(function ($, undefined) { $.widget("mobile.tabs", $.mobile.widget, { options: { iconpos: 'top', grid: null, load: function (event, ui) { }, beforeTabHide: function (event, ui) { }, beforeTabShow: function (event, ui) { }, afterTabShow: function (event, ui) { } }, _create: function () { var $this = this, $tabs = this.element, $navbtns = $tabs.find("a"), iconpos = $navbtns.filter('[data-icon]').length ? this.options.iconpos : undefined; var $content = $tabs.closest('div[data-role="page"]').find('div[data-role="content"]'); $tabs .addClass('ui-navbar') .attr("role", "navigation") .find("ul") .grid({ grid: this.options.grid }); if (!iconpos) { $tabs.addClass("ui-navbar-noicons"); } $navbtns .buttonMarkup({ corners: false, shadow: false, iconpos: iconpos }) .removeClass('ui-link'); // Set up the direct children of the page as the tab content, hide them $content.children().addClass('ui-tabs-content'); // Now show the one that's active if ($navbtns.filter('.ui-btn-active').length == 0) $navbtns.eq(0).addClass('ui-btn-active'); $content.children('#' + $navbtns.eq($this.currentTab()).attr('href')).addClass('ui-tabs-content-active'); $navbtns.bind('click', function (event) { navButtonClick.call(this, event); return false; }) .bind('tap', function (event) { navButtonClick.call(this, event); return false; }); function navButtonClick(event) { $navbtns.removeClass("ui-btn-active"); $(this).addClass("ui-btn-active"); $this.changeTab(event, { currentTab: $navbtns.eq($this.currentTab()), nextTab: $(this), currentContent: $this.currentContent(), nextContent: $content.children($(this).attr('href')) }); event.preventDefault(); } this._trigger('load', null, { currentTab: $navbtns.eq($this.currentTab()), currentContent: $this.currentContent() }); }, currentTab: function () { var $tabs = this.element, $navbtns = $tabs.find("a"); return this.element.find('.ui-btn-active').parent().prevAll().length; }, currentContent: function () { return this.element.closest('div[data-role="page"]').find('div[data-role="content"]').children().filter('.ui-tabs-content-active'); }, changeTab: function (event, ui) { if (this._trigger('beforeTabHide', event, ui)) ui.currentContent.siblings().andSelf().removeClass('ui-tabs-content-active'); if (this._trigger('beforeTabShow', event, ui)) ui.nextContent.addClass('ui-tabs-content-active'); this._trigger('afterTabShow', event, $.extend({}, ui, { previousContent: ui.currentContent, currentContent: ui.nextContent, nextContent: null })); } }); })(jQuery); $('[data-role=page]').live('pagecreate', function(e) { $(this).find('[data-role="tabs"]').tabs(); }); </code></pre> <p>Here is the Html Part of the Page.</p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" /&gt; &lt;link href="css/StyleSheet.css" rel="stylesheet" type="text/css" /&gt; &lt;script src="http://code.jquery.com/jquery-1.6.4.min.js"&gt;&lt;/script&gt; &lt;script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"&gt;&lt;/script&gt; &lt;script src="tab.js" type="text/javascript"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div data-role="page" id="page-title" class="MainClass1" data-theme="c"&gt; &lt;input id="Submit1" type="submit" value="Tab2" data-inline="true" /&gt; &lt;div class="RightCont"&gt; &lt;div data-role="tabs"&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#BattingTab" data-theme="a" class=""&gt;Batting&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#BowlingTab" data-theme="a" class=""&gt;Bowling&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#ExtrasTab" data-theme="a" class=""&gt;Extras&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#DetailsTab" data-theme="a" class=""&gt;Details&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div data-role="content"&gt; &lt;div id="BattingTab"&gt; &lt;/div&gt; &lt;div id="BowlingTab"&gt; &lt;/div&gt; &lt;div id="ExtrasTab"&gt; &lt;/div&gt; &lt;div id="DetailsTab"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload