-1
<div class="pay-way">

<div class="pay-way-menu" id="pay1">
<input type="radio" name="pay-way" value="credit">
<img src="images/credit.png" width="45" height="45" alt=""/><div class="pay-word"></div></div>

<div class="pay-way-menu" id="pay2">
<input type="radio" name="pay-way" value="convenience">
<img src="images/convenience.jpg" width="125" height="35" alt=""/><div class="pay-word"></div></div>

<div class="pay-way-menu" id="pay3">
<input type="radio" name="pay-way" value="atm">
<img src="images/atm.png" width="45" height="45" alt=""/><div class="pay-word"></div></div>

</div>

How to click only one and hide other options? I just start learning and really no ideas about this Thank you so much

sylvia
  • 1
  • 3
  • 6
    Welcome to SO! Please refer [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) and provide necesary details – Rajesh Oct 03 '16 at 06:29
  • Sorry for those unclear details,I will correct and learn as soon as possible Thank you! – sylvia Oct 03 '16 at 06:36
  • its alright. You can refer following posts as reference: [Hide element](http://stackoverflow.com/questions/5375449/how-to-hide-a-div-with-jquery) or [show/hide elements](http://stackoverflow.com/questions/10310717/toggle-show-hide-on-click-with-jquery) – Rajesh Oct 03 '16 at 07:59

3 Answers3

1

You can use hide to hide element. You can also use .not to ignore current clicked element.

$('.pay-way-menu').not(this).hide();

Following is a sample for same:

$('.pay-way-menu').on('click', function(){
  $('.pay-way-menu').not(this).hide();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<div class="pay-way">

  <div class="pay-way-menu" id="pay1">
    <input type="radio" name="pay-way" value="credit">
    <img src="images/credit.png" width="45" height="45" alt="" />
    <div class="pay-word"></div>
  </div>

  <div class="pay-way-menu" id="pay2">
    <input type="radio" name="pay-way" value="convenience">
    <img src="images/convenience.jpg" width="125" height="35" alt="" />
    <div class="pay-word"></div>
  </div>

  <div class="pay-way-menu" id="pay3">
    <input type="radio" name="pay-way" value="atm">
    <img src="images/atm.png" width="45" height="45" alt="" />
    <div class="pay-word"></div>
  </div>
</div>

Reference

Community
  • 1
  • 1
Mohit Tanwani
  • 6,608
  • 2
  • 14
  • 32
0

Using jQuery you can do the following:

$(document).ready(function () {
    // attach click handler to all pay-way-menu
    $(document).on("click", ".pay-way-menu", function() {
       // hide all
       $('.pay-way-menu').hide();

       // show this
       $(this).show();
    });
});

However, you need to think about how you are going to allow users to change their minds.

Ted
  • 3,985
  • 1
  • 20
  • 33
0
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
 $(document).on("click", ".pay-way-menu", function() {
       // hide all expect thie current one
       $('.pay-way-menu').not(this).hide();
    });
});
</script>
</head>
<body>
<div class="pay-way">

<div class="pay-way-menu" id="pay1">
<input type="radio" name="pay-way" value="credit">
<img src="images/credit.png" width="45" height="45" alt=""/><div class="pay-word"></div></div>

<div class="pay-way-menu" id="pay2">
<input type="radio" name="pay-way" value="convenience">
<img src="images/convenience.jpg" width="125" height="35" alt=""/><div class="pay-word"></div></div>

<div class="pay-way-menu" id="pay3">
<input type="radio" name="pay-way" value="atm">
<img src="images/atm.png" width="45" height="45" alt=""/><div class="pay-word"></div></div>

</div>

</body>
</html>
Jobelle
  • 2,717
  • 1
  • 15
  • 26