Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This post shows a complete working HTML file as an example of triggering code to run when a tab is clicked. The .on() method is now the way that jQuery suggests that you handle events.</p> <p><a href="http://learn.jquery.com/events/history-of-events/" rel="nofollow">jQuery development history</a></p> <p>To make something happen when the user clicks a tab can be done by giving the list element an id.</p> <pre><code>&lt;li id="list"&gt; </code></pre> <p>Then referring to the id.</p> <pre><code>$("#list").on("click", function() { alert("Tab Clicked!"); }); </code></pre> <p>Make sure that you are using a current version of the jQuery api. Referencing the jQuery api from Google, you can get the link here:</p> <p><a href="https://developers.google.com/speed/libraries/devguide#jquery" rel="nofollow">https://developers.google.com/speed/libraries/devguide#jquery</a></p> <p>Here is a complete working copy of a tabbed page that triggers an alert when the horizontal tab 1 is clicked. </p> <pre><code>&lt;!-- This HTML doc is modified from an example by: --&gt; &lt;!-- http://keith-wood.name/uiTabs.html#tabs-nested --&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;TabDemo&lt;/title&gt; &lt;link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/themes/south-street/jquery-ui.css"&gt; &lt;style&gt; pre { clear: none; } div.showCode { margin-left: 8em; } .tabs { margin-top: 0.5em; } .ui-tabs { padding: 0.2em; background: url(http://code.jquery.com/ui/1.8.23/themes/south-street/images/ui-bg_highlight-hard_100_f5f3e5_1x100.png) repeat-x scroll 50% top #F5F3E5; border-width: 1px; } .ui-tabs .ui-tabs-nav { padding-left: 0.2em; background: url(http://code.jquery.com/ui/1.8.23/themes/south-street/images/ui-bg_gloss-wave_100_ece8da_500x100.png) repeat-x scroll 50% 50% #ECE8DA; border: 1px solid #D4CCB0; -moz-border-radius: 6px; -webkit-border-radius: 6px; border-radius: 6px; } .ui-tabs-nav .ui-state-active { border-color: #D4CCB0; } .ui-tabs .ui-tabs-panel { background: transparent; border-width: 0px; } .ui-tabs-panel p { margin-top: 0em; } #minImage { margin-left: 6.5em; } #minImage img { padding: 2px; border: 2px solid #448844; vertical-align: bottom; } #tabs-nested &gt; .ui-tabs-panel { padding: 0em; } #tabs-nested-left { position: relative; padding-left: 6.5em; } #tabs-nested-left .ui-tabs-nav { position: absolute; left: 0.25em; top: 0.25em; bottom: 0.25em; width: 6em; padding: 0.2em 0 0.2em 0.2em; } #tabs-nested-left .ui-tabs-nav li { right: 1px; width: 100%; border-right: none; border-bottom-width: 1px !important; -moz-border-radius: 4px 0px 0px 4px; -webkit-border-radius: 4px 0px 0px 4px; border-radius: 4px 0px 0px 4px; overflow: hidden; } #tabs-nested-left .ui-tabs-nav li.ui-tabs-selected, #tabs-nested-left .ui-tabs-nav li.ui-state-active { border-right: 1px solid transparent; } #tabs-nested-left .ui-tabs-nav li a { float: right; width: 100%; text-align: right; } #tabs-nested-left &gt; div { height: 10em; overflow: auto; } &lt;/pre&gt; &lt;/style&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"&gt;&lt;/script&gt; &lt;script&gt; $(function() { $('article.tabs').tabs(); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;header role="banner"&gt; &lt;h1&gt;jQuery UI Tabs Styling&lt;/h1&gt; &lt;/header&gt; &lt;section&gt; &lt;article id="tabs-nested" class="tabs"&gt; &lt;script&gt; $(document).ready(function(){ $("#ForClick").on("click", function() { alert("Tab Clicked!"); }); }); &lt;/script&gt; &lt;ul&gt; &lt;li id="ForClick"&gt;&lt;a href="#tabs-nested-1"&gt;First&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#tabs-nested-2"&gt;Second&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#tabs-nested-3"&gt;Third&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div id="tabs-nested-1"&gt; &lt;article id="tabs-nested-left" class="tabs"&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#tabs-nested-left-1"&gt;First&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#tabs-nested-left-2"&gt;Second&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#tabs-nested-left-3"&gt;Third&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div id="tabs-nested-left-1"&gt; &lt;p&gt;Nested tabs, horizontal then vertical.&lt;/p&gt; &lt;form action="/sign" method="post"&gt; &lt;div&gt;&lt;textarea name="content" rows="5" cols="100"&gt;&lt;/textarea&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="submit" value="Sign Guestbook"&gt;&lt;/div&gt; &lt;/form&gt; &lt;/div&gt; &lt;div id="tabs-nested-left-2"&gt; &lt;p&gt;Nested Left Two&lt;/p&gt; &lt;/div&gt; &lt;div id="tabs-nested-left-3"&gt; &lt;p&gt;Nested Left Three&lt;/p&gt; &lt;/div&gt; &lt;/article&gt; &lt;/div&gt; &lt;div id="tabs-nested-2"&gt; &lt;p&gt;Tab Two Main&lt;/p&gt; &lt;/div&gt; &lt;div id="tabs-nested-3"&gt; &lt;p&gt;Tab Three Main&lt;/p&gt; &lt;/div&gt; &lt;/article&gt; &lt;/section&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.
    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