I have two files index.php and settings.php.
On index.php there is a button which redirects the user to settings.php on click.
<div id="settings">
Settings
</div>
<script>
$("#settings").on
(
"click",
function()
{
window.location.href = "settings.php";
}
);
</script>
There is also a button on settings.php which redirects back to index.php again on click.
<div id="menü">
Menü
</div>
<script>
$("#menü").on("click", redirect("index.php"));
function redirect(url)
{
window.location.replace(url);
}
</script>
But if i click on the buttons "Settings" then settings.php is loading and i get instantly redirected to index.php again.
However, if i use this code, then it does not redirect instantly:
$("#menü").on("click", function() { redirect("index.php");});
Why do i always need to wrap everything in function() if i use such events?