Thursday, July 16, 2009

YUI and Prototype - updating an element

Well currently I'm working a lot with YUI and specially tabs. So one of the first things I wanted todo is to select a tab and this selections should do two things
  • show the content of the tab, happens by default
  • update a div on the page somewhere with some content related to the tab content
so how do you do this?

Quite simple.

<script type="text/javascript">
var myTabs = new YAHOO.widget.TabView('demo');
var tab0 = myTabs.getTab(0);

function handleClick(e,tab) {
${"div_to_update"}.update("I just clicked on my tab!");

tab0.addListener('click', handleClick,tab0);

and as you can see we use the 'update' function from the prototype library.

No comments:

Post a Comment