Reputation: 21
i have a JSP page run with script, the "console.log" or "alert" run normally, but function doesn't work, when i check Chrome dev tool, the id/class still retrives event listener, but it doesn't work(like onclick)
<%@ page import="entity.Product" %>
<%@ page import="entity.Category" %>
<%@ page import="java.util.List" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/Home.css" type="text/css"/>
<link rel="stylesheet" href="css/grid.css" type="text/css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<link rel="stylesheet" href="fontawesome-free-5.15.4-web/css/all.min.css" type="text/css"/>
<link rel="stylesheet" href="css/Header.css" type="text/css"/>
<link rel="stylesheet" href="css/Footer.css" type="text/css"/>
</head>
<script type="text/javascript">
console.log(1); //work normally
function click() { //doesn't work
alert('home');
}
</script>
<body>
<div class="body" onclick="click()">
</div>
</body>
</html>
Upvotes: 0
Views: 44
Reputation: 21
The problem is fixed, you shouldn't name your function "click", it's duplicate with "onclick"
Upvotes: 1