javascript - If/Else statement not functioning properly (Else statement won't function in particular) -


i trying create script manages visibility of content based on whether option selected. issue running if/else statement not functioning properly.

it shows div .provider-info when last .radial-container radio button checked (i.e. "i keep number").

it's supposed slideup when class .select removed parent container, doesn't.

i experimented bit , able gain functionality looking different piece of code:

 $(function() {   $('.radial-container').on('click', function() {     $(this).addclass('select').siblings().removeclass('select');     if($('.radial-container').last().hasclass('select')) {       $(this).children('.provider-info').slidedown(300);     } else {       $('.provider-info').slideup(300);     }   }) }) 

but issue above segment works unlimited line 2. unlimited line 1 loses functionality.

how can fix code in order if/else statement function properly? want div .provider-info visible when 2nd radio button selected.

thanks,

-m

$(function() {    $('.radial-container').on('click', function() {      $(this).addclass('select').siblings().removeclass('select');      if($('.radial-container').hasclass('select')) {        $(this).children('.provider-info').slidedown(300);      } else {        $('.provider-info').slideup(300);      }    })  })
.phn-option-container {  	display:block;  }    .phn-unl {  	position:relative;  	margin:40px 0;  }    .phn-unl:after {  	content:'';  	display:block;  	position:relative;  	background:#e8e8e8;  	height:1px;  	top:30px;  	clear:both;  }    .radial-container {  	display:block;  	cursor: pointer;  	clear:both;  }    .phn-radio-container {  	margin:10px;  	clear:both;  }    .phn-unl > h4 {  	position:relative;  	left:10px;  	font-weight:600;  	color:#22ddc0;  }    .radial-container p {  	position:relative;  	float:left;  	left:25px;  	top:17px;  	color:#787878;  }    .radial-container.select .phn-radial .phn-center-dot {  	display:block;  }    .phn-radial {  	position:relative;  	float:left;  	height:35px;  	width:35px;  	padding:2px;  	margin:10px 0;  	border:5px solid #e8e8e8;  	border-radius:50%;  	left:10px;  	clear:both;  	cursor:pointer;  }    .phn-center-dot {  	display:none;  	position:relative;  	height:21px;  	width:21px;  	background-color:#e16e5b;  	border-radius:50%;  }    .provider-info label {  	color:#787878;  	margin:25px 0 0 60px;  }    .provider-info label span {  	position:relative;  	color:#e16e5b;  	top:-3px;  }    .provider-info input {  	background-color:transparent;  	border-width:0 0 2px;  	border-color:#787878;  	border-radius:0;  	margin-left:10px;  	width:270px;  	font-size:16px;  }    ::-webkit-input-placeholder {     font-style: italic;  }  :-moz-placeholder {     font-style: italic;  }  ::-moz-placeholder {     font-style: italic;  }  :-ms-input-placeholder {     font-style: italic;  }    .provider-info input:focus {  	border-color:#22ddc0;  	outline:0;  }    .provider-info {  	display:none;  	clear:both;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>  <div class="phn-option-container">            <div class="phn-unl" data-unl-line="1">              <h4>unlimited line 1</h4>              <div class="radial-container select">                <div class="phn-radial">                  <div class="phn-center-dot"></div>                </div>                <p>i <strong>new</strong> number</p>              </div>              <div class="radial-container">                <div class="phn-radial">                  <div class="phn-center-dot"></div>                </div>                <p>i <strong>keep</strong> number</p>                <div class="provider-info">                  <div>                    <label>current number: <span>*</span></label>                    <input type="text" placeholder="e.g. (555) 555-5555"/>                  </div>                  <div>                    <label>current provider: <span>*</span></label>                    <input type="text" placeholder="e.g. verizon"/>                  </div>                </div>              </div>            </div>            <div class="phn-unl" data-unl-line="2">              <h4>unlimited line 2</h4>              <div class="radial-container select">                <div class="phn-radial">                  <div class="phn-center-dot"></div>                </div>                <p>i <strong>new</strong> number</p>              </div>              <div class="radial-container">                <div class="phn-radial">                  <div class="phn-center-dot"></div>                </div>                <p>i <strong>keep</strong> number</p>                <div class="provider-info">                  <div>                    <label>current number: <span>*</span></label>                    <input type="text" placeholder="e.g. (555) 555-5555"/>                  </div>                  <div>                    <label>current provider: <span>*</span></label>                    <input type="text" placeholder="e.g. verizon"/>                  </div>                </div>              </div>            </div>          </div>

this should job:

$('.radial-container').on('click', function() {     $(this).addclass('select')            .siblings('.radial-container')            .removeclass('select')            .find('.provider-info')            .slideup(300);     $('.provider-info', this).slidedown(300); }); 

fixed demo:

$(function() {      $('.radial-container').on('click', function() {          $(this).addclass('select')                 .siblings('.radial-container')                 .removeclass('select')                 .find('.provider-info')                 .slideup(300);          $('.provider-info', this).slidedown(300);      });  });
.phn-option-container {  	display:block;  }    .phn-unl {  	position:relative;  	margin:40px 0;  }    .phn-unl:after {  	content:'';  	display:block;  	position:relative;  	background:#e8e8e8;  	height:1px;  	top:30px;  	clear:both;  }    .radial-container {  	display:block;  	cursor: pointer;  	clear:both;  }    .phn-radio-container {  	margin:10px;  	clear:both;  }    .phn-unl > h4 {  	position:relative;  	left:10px;  	font-weight:600;  	color:#22ddc0;  }    .radial-container p {  	position:relative;  	float:left;  	left:25px;  	top:17px;  	color:#787878;  }    .radial-container.select .phn-radial .phn-center-dot {  	display:block;  }    .phn-radial {  	position:relative;  	float:left;  	height:35px;  	width:35px;  	padding:2px;  	margin:10px 0;  	border:5px solid #e8e8e8;  	border-radius:50%;  	left:10px;  	clear:both;  	cursor:pointer;  }    .phn-center-dot {  	display:none;  	position:relative;  	height:21px;  	width:21px;  	background-color:#e16e5b;  	border-radius:50%;  }    .provider-info label {  	color:#787878;  	margin:25px 0 0 60px;  }    .provider-info label span {  	position:relative;  	color:#e16e5b;  	top:-3px;  }    .provider-info input {  	background-color:transparent;  	border-width:0 0 2px;  	border-color:#787878;  	border-radius:0;  	margin-left:10px;  	width:270px;  	font-size:16px;  }    ::-webkit-input-placeholder {     font-style: italic;  }  :-moz-placeholder {     font-style: italic;  }  ::-moz-placeholder {     font-style: italic;  }  :-ms-input-placeholder {     font-style: italic;  }    .provider-info input:focus {  	border-color:#22ddc0;  	outline:0;  }    .provider-info {  	display:none;  	clear:both;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>  <div class="phn-option-container">            <div class="phn-unl" data-unl-line="1">              <h4>unlimited line 1</h4>              <div class="radial-container select">                <div class="phn-radial">                  <div class="phn-center-dot"></div>                </div>                <p>i <strong>new</strong> number</p>              </div>              <div class="radial-container">                <div class="phn-radial">                  <div class="phn-center-dot"></div>                </div>                <p>i <strong>keep</strong> number</p>                <div class="provider-info">                  <div>                    <label>current number: <span>*</span></label>                    <input type="text" placeholder="e.g. (555) 555-5555"/>                  </div>                  <div>                    <label>current provider: <span>*</span></label>                    <input type="text" placeholder="e.g. verizon"/>                  </div>                </div>              </div>            </div>            <div class="phn-unl" data-unl-line="2">              <h4>unlimited line 2</h4>              <div class="radial-container select">                <div class="phn-radial">                  <div class="phn-center-dot"></div>                </div>                <p>i <strong>new</strong> number</p>              </div>              <div class="radial-container">                <div class="phn-radial">                  <div class="phn-center-dot"></div>                </div>                <p>i <strong>keep</strong> number</p>                <div class="provider-info">                  <div>                    <label>current number: <span>*</span></label>                    <input type="text" placeholder="e.g. (555) 555-5555"/>                  </div>                  <div>                    <label>current provider: <span>*</span></label>                    <input type="text" placeholder="e.g. verizon"/>                  </div>                </div>              </div>            </div>          </div>


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -