'click function is not working sometimes in jquery
I have done this work to print row-wise data with jquery for that I have made the below code in this code when I click on print button it is working sometimes print window opens and some times not some times I have to click 2-3 times to open window
$(document).ready(function() {
$('.print').click(function() {
var id = $(this).attr('id');
var newWin = window.open();
$.ajax({
type: "GET",
url: '{{route('admin.letter_head.print')}}',
data: {
id: id
},
success: function(data) {
newWin.document.write(data);
newWin.document.close();
newWin.focus();
newWin.print();
newWin.close();
},
error: function() {}
});
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<table id="LetterHeadList" class="table dt-table-hover dataTable">
<thead>
<tr>
<th>Title</th>
<th class="not-mobile">Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>title1 update</td>
<td style="display: flex;">
<button class="btn mb-2 mr-2 rounded-circle btn-outline-primary print" id="1">print</button>
</td>
</tr>
<tr>
<td>title2</td>
<td style="display: flex;">
<button class="btn mb-2 mr-2 rounded-circle btn-outline-primary print" id="2">print</button>
</td>
</tr>
</tbody>
</table>
can anybody help me in this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
