Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery tabs MVC avoid duplicate tabs
    text
    copied!<p>i have a series of links when clicked adds tab using jquery.</p> <pre><code>function addTab(title, uri) { var newTab = $("#tabs").tabs("add", uri, title); } </code></pre> <p>I want only one tabs per link. if users keeps pressing the link it keeps adding new tabs to that div.</p> <p>one way i was thinking was adding a id to anchor that that is created inside the li of the Tab by jquery but i don;t see how to do that so</p> <pre><code>&lt;li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"&gt;&lt;a href="#ui-tabs-4"&gt;&lt;span&gt;Ncollison Collison&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; </code></pre> <p>instead of justtab number that jquery gives i want to add id with unique value that i will pass to the method. so this <code>&lt;a href="#ui-tabs-4"&gt;</code> becomes <code>&lt;a href="#ui-tabs-4" id="12323"&gt;</code> so i can check for this id before i add another tab. i am not sure how to add this unique value to the tab anchor right after i add the tab in method above addTab(title, uri, uniquevlaue) .</p> <p><strong>EDIT1</strong></p> <pre><code>$(function () { $('#tabs').tabs( { cache: true }, { ajaxOptions: { cache: false, error: function (xhr, status, index, anchor) { $(anchor.hash).html("Couldn't load this tab."); }, data: {}, success: function (data, textStatus) { } }, add: function (event, ui) { //select the new tab $('#tabs').tabs('select', '#' + ui.panel.id); } }); }); function addTab(title, uri) { // If tab already exist in the list, return if ($("#" + title).length != 0) return; var newTab = $("#tabs").tabs("add", uri, title); } function closeTab() { var index = getSelectedTabIndex(); $("#tabs").tabs("remove", index) } function getSelectedTabIndex() { return $("#tabs").tabs('option', 'selected'); } function RefershList() { $('#frmPeopleList').submit(); } &lt;div id="tabs"&gt; &lt;ul&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>I have links that call this similar to below</p> <pre><code> &lt;input id="btnAddTab" type="button" onclick="addTab('Add Person','&lt;%= Url.Action("Create", "People") %&gt;')" value='Add New Person' /&gt; </code></pre> <p><strong>EDIT 2</strong> Generated HTML</p> <pre><code>&lt;div id="tabs" class="ui-tabs ui-widget ui-widget-content ui-corner-all"&gt; &lt;ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all"&gt; &lt;li class="ui-state-default ui-corner-top"&gt;&lt;a href="#ui-tabs-2"&gt;&lt;span&gt;Rwestbrook Westbrook&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;li class="ui-state-default ui-corner-top"&gt;&lt;a href="#ui-tabs-4"&gt;&lt;span&gt;Rwestbrook Westbrook&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;li class="ui-state-default ui-corner-top"&gt;&lt;a href="#ui-tabs-6"&gt;&lt;span&gt;Rwestbrook Westbrook&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;li class="ui-state-default ui-corner-top"&gt;&lt;a href="#ui-tabs-8"&gt;&lt;span&gt;Rwestbrook Westbrook&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"&gt;&lt;a href="#ui-tabs-10"&gt;&lt;span&gt;Rwestbrook Westbrook&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div id="ui-tabs-2" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide"&gt;&lt;h2&gt;Chat&lt;/h2&gt; &lt;input type="text" value=" " id="msg"&gt; &lt;input type="button" value="send" id="send"&gt; &lt;ul id="message"&gt; &lt;/ul&gt;&lt;/div&gt;&lt;div id="ui-tabs-4" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide"&gt;&lt;h2&gt;Chat&lt;/h2&gt; &lt;input type="text" value=" " id="msg"&gt; &lt;input type="button" value="send" id="send"&gt; &lt;ul id="message"&gt; &lt;/ul&gt;&lt;/div&gt;&lt;div id="ui-tabs-6" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide"&gt;&lt;h2&gt;Chat&lt;/h2&gt; &lt;input type="text" value=" " id="msg"&gt; &lt;input type="button" value="send" id="send"&gt; &lt;ul id="message"&gt; &lt;/ul&gt;&lt;/div&gt;&lt;div id="ui-tabs-8" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide"&gt;&lt;h2&gt;Chat&lt;/h2&gt; &lt;input type="text" value=" " id="msg"&gt; &lt;input type="button" value="send" id="send"&gt; &lt;ul id="message"&gt; &lt;/ul&gt;&lt;/div&gt;&lt;div id="ui-tabs-10" class="ui-tabs-panel ui-widget-content ui-corner-bottom"&gt;&lt;h2&gt;Chat&lt;/h2&gt; &lt;input type="text" value=" " id="msg"&gt; &lt;input type="button" value="send" id="send"&gt; &lt;ul id="message"&gt; &lt;/ul&gt;&lt;/div&gt; &lt;div id="ui-tabs-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom"&gt;&lt;/div&gt;&lt;div id="ui-tabs-3" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide"&gt;&lt;/div&gt;&lt;div id="ui-tabs-5" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide"&gt;&lt;/div&gt;&lt;div id="ui-tabs-7" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide"&gt;&lt;/div&gt;&lt;div id="ui-tabs-9" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide"&gt;&lt;/div&gt;&lt;/div&gt; </code></pre> <p>URI sent is '/Chat/AddChat</p>
 

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