javascript - HTML page reloads automatically -


i have html page given below:

$(document).ready(function() {    var showchar = 380;    var ellipsestext = "...";    var moretext = "read more";    var lesstext = "read less";    var lesshtml="";    var morehtml="";    var content = $(".more").html();      if(content.length > showchar) {        var lastchar = content.charat(showchar);      if(lastchar == '/'){        showchar = showchar+1;      }      var c = content.substr(0, showchar);      var h = content.substr(showchar-1, content.length - showchar);        var lesshtml = c + '<span class="moreelipses">'+ellipsestext+' <a href="" class="morelink">'+moretext+'</a></span>';      var morehtml = content + '<span><a href="" class="morelink">'+lesstext+'</a></span>';      $(".more").html(lesshtml);    }      $(".morelink").click(function(){        if ($(this).text()==moretext){        $(".more").html(morehtml);      }else{        $(".more").html(lesshtml);      }      return false;    });  });
a {    color: #ea7813  }  a:visited {    color: #ea7813	  }  a.morelink {    text-decoration:none;    outline: none;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>    <div class="more">    <p>can't reach light switch when walk room? need 1 added near door? if have switch professionally installed in location no switch exists, 1 of our vetted, <strong>local electrical professionals</strong> take care of <strong>light switch installation </strong>and make sure it's working smoothly.</p>    <p><strong>what's included:</strong></p>    <ul>      <li>install 1 (1) new gang box , associated wiring extension existing circuit (up 25')</li>      <li>install , pair 1 (1) <strong>customer-supplied</strong> smart light switch in new location <strong>-or-</strong> provide , install 1 (1) standard single-pole switch , cover plate</li>      <li>ensure features operating maximum performance</li>      <li>demonstrate basic device features</li>      <li>90-day labor warranty</li>    </ul>    <p><strong>out of scope:</strong></p>    <ul>      <li>smart switch not included, price includes installation of smart switch -or- providing , installing standard switch</li>      <li>requires existing, accessible electrical circuit within 25'</li>      <li>drywall patching &amp; painting</li>      <li>requires existing, compatible network</li>      <li>no diagnostic, repair or parts included service</li>      <li>no non-stock parts, materials or system repair / upgrades included service</li>    </ul>  </div>

what want expand , shrink body. expansion works fine when shrink, page reloads. want stop reloading. in click function, else part never fired. instead, page reloads. want stop reloading , run code in else body shrinks appropriately.

delegate event

 $('body').on('click','.morelink',function(e){    e.preventdefault();    //other code   }); 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -