Created
March 23, 2014 10:51
-
-
Save ClausPolanka/9721539 to your computer and use it in GitHub Desktop.
Schoki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Schoki</title> | |
<link rel="stylesheet" href="styles.css"> | |
</head> | |
<body> | |
<a class="menu" href="#">Home</a> | |
<a class="menu" href="#">Services</a> | |
<a class="menu" href="#">About</a> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.js"></script> | |
<script> | |
(function() { | |
var currentMenuText = ''; | |
var menuItems = $('a.menu'); | |
menuItems.hover( | |
function () { | |
var currentMenu = $(this); | |
var text = currentMenu.text(); | |
if (text.indexOf('[ ') == -1) { | |
currentMenu.text('[ ' + text + ' ]'); | |
}; | |
}, | |
function () { | |
replaceBracketsOf(this, currentMenuText); | |
}); | |
menuItems.click(function() { | |
currentMenuText = $(this).text(); | |
menuItems.each(function() { | |
replaceBracketsOf(this, currentMenuText); | |
}); | |
}); | |
})(); | |
function replaceBracketsOf(element, currentMenuText) { | |
var currentMenu = $(element); | |
var text = currentMenu.text(); | |
if (text != currentMenuText) { | |
text = text.replace('[ ', '') | |
.replace(' ]', ''); | |
currentMenu.text(text); | |
}; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment