Java Reference
In-Depth Information
if (target.className == "tabStrip-tab-hover") {
target.className = "tabStrip-tab-click";
var num = target.getAttribute("data-tab-number");
showDescription(num);
}
break;
}
}
function showDescription(num) {
var text = "Description for Tab " + num;
descContainer.innerHTML = text;
}
document.addEventListener("mouseover", handleEvent);
document.addEventListener("mouseout", handleEvent);
document.addEventListener("click", handleEvent);
</script>
</body>
</html>
Save this file as ch10_example9.html . Open it in your browser, and when you move your mouse pointer
over a tab, its style changes to a blue background with a darker blue border. When you click a tab, its
style changes yet again to make the tab's background color a light orange with a darker orange border
color. Also, when you click a tab, text is added to the page. For example, clicking tab 3 results in the
text “Description for Tab 3” being added to the page.
Take a look at the HTML in the body, and its style, first:
<div class="tabStrip">
<div data-tab-number="1" class="tabStrip-tab">Tab 1</div>
<div data-tab-number="2" class="tabStrip-tab">Tab 2</div>
<div data-tab-number="3" class="tabStrip-tab">Tab 3</div>
</div>
<div id="descContainer"></div>
The first <div/> element has a CSS class of tabStrip . The three <div/> elements contained within it
represent three tabs. Each tab <div/> element has a numeric value assigned to its data‐tab‐number
attribute, and a CSS class of tabStrip‐tab .
The tab strip <div/> element has a sibling <div/> element with an id value of descContainer . It doesn't
contain any children, and it doesn't have a CSS class associated with it.
In this example, the tab strip is visually set apart from the rest of the page by giving it a gray
background:
.tabStrip {
background-color: #E4E2D5;
padding: 3px;
height: 22px;
}
Search WWH ::




Custom Search