I haven't been able to find a clearly defined solution for this. Most are incomplete snippets.
Here is a simple sample. See the doSomething() comment:
<head>
<style type="text/css">
body, html { font-family:helvetica,arial,sans-serif; font-size:90%; }
</style>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/claro.css"/>
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js"
djConfig="parseOnLoad: true">
</script>
<script type="text/javascript">
dojo.require("dijit.layout.TabContainer");
dojo.require("dijit.layout.ContentPane");
function doSomething() {
//Put code in here that identifies the clicked tab and displays it's id in the below alert
alert("Hello World!");
}
</script>
</head>
<body class=" claro ">
<div id="mainTab" dojoType="dijit.layout.TabContainer" style="width: 400px; height: 100px;" onClick="doSomething();">
<div id="tab1" dojoType="dijit.layout.ContentPane" title="My first tab" selected="true">
Lorem ipsum and all around...
</div>
<div id="tab2" dojoType="dijit.layout.ContentPane" title="My second tab">
Lorem ipsum and all around - second...
</div>
<div id="tab3" dojoType="dijit.layout.ContentPane" title="My last tab">
Lorem ipsum and all around - last...
</div>
</div>
</body>
Here's a complete code sample that works in Dojo 1.8, I've tested it:
Try this:
You could attach to the selectChild event on TabContainer using
dojo.connect
. Something likeYou can also do this by doing a
dojo.subscribe
to the mainTab-selectChild topic.I believe
dijit.byId('mainTab').selectedChildWidget
ought to give you a reference to the widget in the selected tab (e.g. one of your ContentPanes).http://www.dojotoolkit.org/api/dijit/layout/TabContainer.html#selectedChildWidget