Answer the question
In order to leave comments, you need to log in
Why doesn't javascript work in php?
Added insert header and footer to all pages, js stopped working. The code is executed, it is visible in the console, but the page seems to be frozen.
<?php
require "blocks/header.php";
?>
<div class="container prices">
<br>
<p>
<button style="margin-right: 20px; "id="btn" type="button" class="btn btn-primary active btn-lg">Шугаринг</button>
<button id="btn" type="button" class="btn btn-default btn-lg">Массаж</button>
</p>
<br>
<!-- СТОИМОСТЬ УСЛУГ ШУГАРИНГА -->
<table class="table table-bordered">
<thead>
</tbody>
</table>
<!-- СТОИМОСТЬ УСЛУГ МАССАЖА -->
<table class="btn-service table table-bordered">
<thead>
<tr>
<th>УСЛУГА</th>
<th>СТОИМОСТЬ</th>
<th>ВРЕМЯ</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<br>
<?php
require "blocks/footer.php";
echo "<script type="text/javascript" src="js/javascript.js"></script>";
?>
<div id="footer">
<div class="container">
<div class="row centered">
<a href="#"><i class="fa fa-whatsapp"></i></a>
<a href="#"><i class="fa fa-instagram"></i></a>
<a href="#"><i class="fa fa-vk"></i></a>
</div>
</div>
</div>
<script type="text/javascript" src="js/javascript.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/npm.js"></script>
</body>
</html>
var btn1 = document.getElementsByClassName('btn');
var table1 = document.getElementsByClassName('table');
console.log(btn1);
for (var i = 0; i < btn1.length; i++) {
btn1[1].addEventListener('click', function(){
if (btn1[1]) {
for (var i = 0; i < table1.length; i++) {
table1[i].classList.add('btn-service');
btn1[i].classList.remove('btn-default', 'btn-primary', 'active');
}
table1[1].classList.remove('btn-service');
btn1[1].classList.add('btn-primary', 'active');
}
});
btn1[0].addEventListener('click', function(){
if (btn1[0]) {
for (var i = 0; i < table1.length; i++) {
table1[i].classList.add('btn-service');
btn1[i].classList.remove('btn-default', 'btn-primary', 'active');
}
table1[0].classList.remove('btn-service');
btn1[0].classList.add('btn-primary', 'active');
}
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question