JavaScript/jQuery not loading correctly automatically -


when page first loads shows prices until click option. cannot java run @ start monthly price.

if want see it.

http://www.infinityhost.net/web-hosting-plans.htm

i attached 3 parts of code.

i have looked on million times , can't find makes load 1 month section automatically.

// ______________  price switch        $(window).load(function() {            $(".price-per-period .per1").click(function() {              $(".per1a").show();  			$(".per3a").hide();              $(".per6a").hide();              $(".per12a").hide();  			$(".per24a").hide();              $(".price-per-period .per1").addclass("btn-shared-checked");              $(".price-per-period .per1").removeclass("btn-default");              $(".price-per-period .per3").removeclass("btn-shared-checked");              $(".price-per-period .per3").addclass("btn-default");              $(".price-per-period .per6").removeclass("btn-shared-checked");              $(".price-per-period .per6").addclass("btn-default");  			$(".price-per-period .per12").removeclass("btn-shared-checked");              $(".price-per-period .per12").addclass("btn-default");  			$(".price-per-period .per24").removeclass("btn-shared-checked");              $(".price-per-period .per24").addclass("btn-default");          });  		  		$(".price-per-period .per3").click(function() {              $(".per1a").hide();  			$(".per3a").show();              $(".per6a").hide();              $(".per12a").hide();  			$(".per24a").hide();              $(".price-per-period .per1").removeclass("btn-shared-checked");              $(".price-per-period .per1").addclass("btn-default");              $(".price-per-period .per3").addclass("btn-shared-checked");              $(".price-per-period .per3").removeclass("btn-default");              $(".price-per-period .per6").removeclass("btn-shared-checked");              $(".price-per-period .per6").addclass("btn-default");  			$(".price-per-period .per12").removeclass("btn-shared-checked");              $(".price-per-period .per12").addclass("btn-default");  			$(".price-per-period .per24").removeclass("btn-shared-checked");              $(".price-per-period .per24").addclass("btn-default");          });            $(".price-per-period .per6").click(function() {              $(".per1a").hide();  			$(".per3a").hide();              $(".per6a").show();              $(".per12a").hide();  			$(".per24a").hide();              $(".price-per-period .per1").removeclass("btn-shared-checked");              $(".price-per-period .per1").addclass("btn-default");              $(".price-per-period .per3").removeclass("btn-shared-checked");              $(".price-per-period .per3").addclass("btn-default");              $(".price-per-period .per6").addclass("btn-shared-checked");              $(".price-per-period .per6").removeclass("btn-default");  			$(".price-per-period .per12").removeclass("btn-shared-checked");              $(".price-per-period .per12").addclass("btn-default");  			$(".price-per-period .per24").removeclass("btn-shared-checked");              $(".price-per-period .per24").addclass("btn-default");          });            $(".price-per-period .per12").click(function() {              $(".per1a").hide();  			$(".per3a").hide();              $(".per6a").hide();              $(".per12a").show();  			$(".per24a").hide();              $(".price-per-period .per1").removeclass("btn-shared-checked");              $(".price-per-period .per1").addclass("btn-default");              $(".price-per-period .per3").addclass("btn-default");              $(".price-per-period .per3").removeclass("btn-shared-checked");              $(".price-per-period .per6").addclass("btn-default");              $(".price-per-period .per6").removeclass("btn-shared-checked");  			$(".price-per-period .per12").addclass("btn-shared-checked");              $(".price-per-period .per12").removeclass("btn-default");  			$(".price-per-period .per24").removeclass("btn-shared-checked");              $(".price-per-period .per24").addclass("btn-default");          });  		  		$(".price-per-period .per24").click(function() {              $(".per1a").hide();  			$(".per3a").hide();              $(".per6a").hide();              $(".per12a").hide();  			$(".per24a").show();              $(".price-per-period .per1").removeclass("btn-shared-checked");              $(".price-per-period .per1").addclass("btn-default");              $(".price-per-period .per3").addclass("btn-default");              $(".price-per-period .per3").removeclass("btn-shared-checked");              $(".price-per-period .per6").addclass("btn-default");              $(".price-per-period .per6").removeclass("btn-shared-checked");  			$(".price-per-period .per12").removeclass("btn-shared-checked");              $(".price-per-period .per12").addclass("btn-default");  			$(".price-per-period .per24").addclass("btn-shared-checked");              $(".price-per-period .per24").removeclass("btn-default");          });  		});
<span class="chooseprice">choose price per period</span>                  <div class="btn-group price-per-period" role="group">  <button type="button" class="btn btn-shared-checked per1">1 month</button>  <button type="button" class="btn btn-default per3">3 months</button>  <button type="button" class="btn btn-default per6">6 months</button>  <button type="button" class="btn btn-default per12">1 year</button>  <button type="button" class="btn btn-default per24">2 years</button>                  </div>                      <div class="col-sm-3 wow fadeinup" data-wow-delay="0.4s">                  <div class="panel panel-info">                      <div class="panel-heading">                          <h3 class="text-center">easy</h3></div>                                                                              <div class="panel-body text-center">                          <div class="per1a">                              <h4>$2.99</h4>                              <span class="per">1 month</span>                          </div>                          <div class="per3a">                              <h4>$9.00</h4>                              <span class="per">3 months</span>                          </div>                          <div class="per6a">                              <h4>$15.00</h4>                              <span class="per">6 months</span>                          </div>                          <div class="per12a">                              <h4>$27.00</h4>                              <span class="per">12 months</span>                          </div>                          <div class="per24a">                              <h4>$54.00</h4>                              <span class="per">24 months</span>                          </div>                      </div> 

all of code governing items shown resides in click listeners of different buttons. when no button clicked, none of code executed. of elements visible in markup, , you're not executing javascript on page load tries change that.

either define starting behavior in markup, adding style="display: none;" divs want hidden, or simulate click on page load: $(".price-per-period .per1").click();

on note, code repetitive. save lot of code if buttons , panels had common classes, address them in 1 select, , if extract click listeners 1 common function.

if .per1a, .per2a etc had class per-a, this:

function setactivepanel(name) {    $('.per-a').hide();    $('.'+name).show(); } 

then call setactivepanel('per1a') or setactivepanel('per2a'), etc.

for buttons, assign single click listener:

$('.price-per-period .btn').click(function() {     $('.price-per-period .btn')       .removeclass('btn-shared-checked')       .addclass('btn-default');     $(this)       .addclass('btn-shared-checked')       .removeclass('btn-default');     // need call correct setactivepanel  }); 

for setactivepanel, add data attribute:

<button type="button" class="btn btn-shared-checked per1" data-target="per1a">1 month</button> 

then in click listener, access so:

setactivepanel($(this).data('target')); 

now you've refactored, might find easiest way solve original problem have domready listener call setactivepanel('per1a');


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -