single click and double click issue

Rafael

I have these functions that execute once a link is clicked. For some reason though when the link is clicked once it doesn't open. You have to double-click. After the page has been visited it only requires the link to be clicked once. How do I fix this so it only requires one click.

function indexClick() {
  $("#home").on("click", function() {
    $('.indexPicWrapper').css('display', 'block');
    $('.aboutPicWrapper').css('display', 'none');
  })
}

function aboutClick() {

  $("#about").on("click", function() {
    $(".indexPicWrapper").css("display", "none")
    $('.contactPicWrapper').css('display', 'none');
    $('.aboutPicWrapper').css('display', 'block');
  })
}
nav {
  height: 50px;
  background-color: #eaeaea;
  line-height: 50px;
  text-align: center;
}
.indexPicWrapper {
  min-height: 100%;
  height: 100%;
  width: 100%;
  overflow-y: hidden;
  background: #FFA10D;
  position: absolute;
}
.aboutPicWrapper {
  display: none;
  position: absolute;
  height: 100%;
  width: 100%;
  overflow-y: hidden;
  background-color: #FF510D;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<nav>
  <a id="home" onclick="indexClick()" class="indexLink" href="#">Home</a>
  <a id="about" class="aboutLink" onclick="aboutClick()" href="#">About</a>
</nav>


<div class="indexPicWrapper">
  <h1>Things...</h1>
</div>

<div class="aboutPicWrapper">
  <h1>About...</h1>
</div>

Vitorino fernandes

add event.preventDefault(); for click event and directly write onclick no need to write function

$("#home").on("click", function(event) {
  event.preventDefault();
  $('.indexPicWrapper').css('display', 'block');
  $('.aboutPicWrapper').css('display', 'none');
})

$("#about").on("click", function(event) {
  event.preventDefault()
  $(".indexPicWrapper").css("display", "none")
  $('.contactPicWrapper').css('display', 'none');
  $('.aboutPicWrapper').css('display', 'block');
})
nav {
  height: 50px;
  background-color: #eaeaea;
  line-height: 50px;
  text-align: center;
}
.indexPicWrapper {
  min-height: 100%;
  height: 100%;
  width: 100%;
  overflow-y: hidden;
  background: #FFA10D;
  position: absolute;
}
.aboutPicWrapper {
  display: none;
  position: absolute;
  height: 100%;
  width: 100%;
  overflow-y: hidden;
  background-color: #FF510D;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<nav>
  <a id="home" class="indexLink" href="#">Home</a>
  <a id="about" class="aboutLink" href="#">About</a>
</nav>


<div class="indexPicWrapper">
  <h1>Things...</h1>
</div>

<div class="aboutPicWrapper">
  <h1>About...</h1>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Java : ignore single click on double click?

Distinguish between a single click and a double click in Java

Treat Single Click and Double Click as same

Single click blocks double click in tkinter

Separate action for single click and double click with RxJs

Single click in selenium acts as double click

execute either single click or double click . Not both

Why double click instead of single?

Close menu on overlay click requires double click instead of single click

click event works only on double click in stead of a single click

Prevent single click on WPF control when double click occured

Start Editing a TableCell on single click instead of double click

fancy box not open in single click,require double click

Double-click instead of single-click in Ubuntu 12.04

How to differentiate single click event and double click event?

how to trigger a double click on a single click using jquery

Changing <input type= color> behaviour from single click to double click

How to Make a Button Perform Single Click Instead of Double Click

Prevent default single click event on double click on a link in HTML

Change single click as double click to specific element (e.g 'a')

Single click and Double click on the same element, not working; Javascript

Windows 10 Double-clicks on single click

Trouble with a single click on my button. Click event working only for double click

How to prevent a double execution of a single-click event when actually trying to trigger a double click event?

Javascript targeting the first element only with a double click issue

Double click event for a select tag. issue with Firefox

js differ click and double click

Javafx 2 click and double click

Prevent a double-click being interpreted as two single-clicks?