G
G
Gura2015-12-11 16:55:48
PHP
Gura, 2015-12-11 16:55:48

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

1 answer(s)
A
Alexander Wolf, 2015-12-11
@Gudzera

<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 question

Ask a Question

731 491 924 answers to any question