Java Reference
In-Depth Information
}
.tabStrip-tab-hover {
border: 1px solid #316AC5;
background-color: #C1D2EE;
padding: 2px;
}
.tabStrip-tab-click {
border: 1px solid #facc5a;
background-color: #f9e391;
padding: 2px;
}
</style>
</head>
<body>
<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>
<script src="jquery-2.1.1.min.js"></script>
<script>
function handleEvent(e) {
var target = $(e.target);
var type = e.type;
if (type == "mouseover" || type == "mouseout") {
target.toggleClass("tabStrip-tab-hover");
} else if (type == "click") {
target.addClass("tabStrip-tab-click");
var num = target.attr("data-tab-number");
showDescription(num);
}
}
function showDescription(num) {
var text = "Description for Tab " + num;
$("#descContainer").text(text);
}
$(".tabStrip > div").on("mouseover mouseout click", handleEvent);
</script>
</body>
</html>
Save this as ch16 _ example1.html and open it in your browser and notice that its behavior is identical
to that of ch10 _ example17.html .
If you compare this example with ch10 _ example17.html , you'll notice quite a few differences in the
code's structure. Let's start with the very last line of code where you register the event listeners. Your
Search WWH ::




Custom Search