mercredi 17 avril 2019

print specific div content not showing javascript

i want to print specific div by javascript. it is working fine when printed without any html tag. but when use any html tag like p, h1 or h2 it is printed blank page.

here is my code

    @extends('layout.master')
    @section('content')
    <div class="separator-breadcrumb border-top">
    </div>
    <div class="row">
         <div class="col-md-12">
              <div class="card">
                  <div class="card-header bg-secondary" style="padding: 7px 1.25rem">
                      <div class="row">
                          <div class="col-md-1">
                               <button onclick="printDiv('printMe')" class="btn btn-danger font-weight-700"> Print
                               </button>
                          </div>
                      </div>
                  </div>
                 <div id="printMe" >
                       <div class="card-body">
                          <h1>
                            Print this only
                          </h1>
                      </div>
                 </div>
              </div>
          </div>
       </div>
   @endsection
    @section('JScript')
      <script>
         function printDiv(divID) {
            var divElements = document.getElementById(divID).innerHTML;
        var oldPage = document.body.innerHTML;
        document.body.innerHTML = divElements;
        window.print();
        document.body.innerHTML = oldPage;
        }
      </script>
  @endsection



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire