Answer the question
In order to leave comments, you need to log in
How to call a JS function in two ways?
There was a problem, you need to call the js function in two different ways, starting from the GET request, that is, if there is $_GET['id'] then the function should be loaded on page load (automatically), if not, then by clicking on the element.
What can you advise?
Answer the question
In order to leave comments, you need to log in
<script>
function rar() {
alert('Rar!');
}
</script>
<script>
<?php
if(isset($_GET['id'])) {
echo "rar();";
} else {
echo "$('#element').click(rar);";
} ?>
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question