Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div>
- <a href='#' id='link1' onclick='toggle(this)'>link 1</a>
- <a href='#' id='link2' onclick='toggle(this)'>link 2</a>
- <a href='#' id='link3' onclick='toggle(this)'>link 3</a>
- <a href='#' id='link4' style='display:none' onclick='toggle(this)'>link 4</a>
- </div>
- var disp = false;
- function toggle(el) {
- if (disp) {
- if (el.id == 'link4') {
- document.getElementById('link4').style.display='none';
- disp = false;
- }
- } else {
- if ((el.id == 'link1') || (el.id == 'link2') || (el.id == 'link3')) {
- document.getElementById('link4').style.display='block';
- disp = true;
- }
- }
- }
- var disp = false;
- function toggle(el) {
- if (disp) {
- if (el.id == 'link4') {
- $('#link4').fadeOut();
- disp = false;
- }
- } else {
- if ((el.id == 'link1') || (el.id == 'link2') || (el.id == 'link3')) {
- $('#link4').fadeIn();
- disp = true;
- }
- }
- }
- var 3rdLink = $("#3rdLinkId"),
- 4thLink = $("#4thLinkId"); //just good practice
- 3rdLink.on('click', function(event){
- event.preventDefault(); //just in case it's a hyperlink
- 4thLink.css('visibility', 'visible');
- )};
- <a href="#" class="show" onclick="show4()" >link 1</a>
- <a href="#" class="show" onclick="show4()" >link 2</a>
- <a href="#" class="show" onclick="show4()" >link 3</a>
- <a href="#" id="link4" class="hide" onclick="hide4()" >link 4</a>
- <style>
- .hide {display: none;}
- .show {display: block;}
- </style>
- <script>
- function show4()
- {
- document.getElementById('link4').style.display = "block";
- }
- function hide4()
- {
- document.getElementById('link4').style.display = "none";
- }
- </script>
- <div id="link-container">
- <a href="#">link1</a>
- <a href="#">link2</a>
- <a href="#">link3</a>
- <a href="#">link4</a>
- </div>
- #link-container a:last-child{display:none}
- $(function(){
- $('#link-container').on('click', 'a',function(e){
- var $t = $(this),
- $last = $t.siblings('a').addBack().last();
- if($last[0] != this){
- $last.toggle();
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement