<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script type="javascript" src="despage/javascript/script.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript">
function alert() {
alert("hello");
}
$(document).ready(function() {
("p").click(function() {
$(this).hide();
});
});
</script>
<meta charset="ISO-8859-1">
<title>home</title>
</head>
<body>
<h1 style="text-align:center;font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;font-weight: bolder;color:rgb(222, 222, 222);">HEAD</h1></div>
<p onclick="alert()">this one is for test</p>
</body>
I used cdn url for jquery it didnt work ,network connection was stable.simple alert() function onclick on the p tag was working until i wrote that alert function call in the script tag
CodePudding user response:
You've created an infinitely recursive function here:
function alert() {
alert("hello");
}
When you call alert()
, it internally calls alert()
, which internally calls alert()
, which internally calls alert()
, and so on forever.
You don't need to write an alert
function in the browser. It already has one. Just remove this function of yours entirely.
Additionally, a string has no function called click
:
("p").click(/*...*/)
You're probably looking to use that string as a jQuery selector:
$("p").click(/*...*/)
Also, don't use inline click handlers:
<p onclick="alert()">
Remove the handler from there:
<p>
And, since you're using jQuery, just use jQuery to attach a click handler:
$("p").click(/*...*/)
Overall, it sounds like the click handler you want is simply:
$("p").click(function() {
$(this).hide();
alert("hello");
});
(Which should, in this structure, still remain inside your document
's ready
handler.)