i am trying to add class on on-click jquery event for that i am doing
my html file
<head>
<style type="text/css">
.red{ color:red; }
</style>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="js.js"></script>
</head>
<body>
<ul id="list">
<li><a href="">1</a></li>
<li><a href="">2</a></li>
</ul>
</body>
javascript file js.js is
$(document).ready(function(){
$("li").onclick(function(){ // if i comment this and only add the line billow the all ul>li will red
$("#list").addClass("red");
});
});
when i click on the li the color of li will become the red the thing makes me confuse that on-click i am adding the class .red to the ul so the both link should be red but on click only the link i clicked become red

You’re confusing jQuery’s
.click()method with the vanilla JavaScriptelement.onclick = functionRef;In your code sample, you want: