I am working on a click event at the front.
Click Tuesday and Thursday to activate the click function.
But I want to make it work only when I click two or four.
Please refer to the code below.
<li >
<span style="" >
화<em date="2022-08-02" >2</em>
</span>
</li>
<li >
<span style="" >
목<em date="2022-08-04">4</em>
</span>
</li>
js click code (i try)
$("li > span > em").click(function () {
$("li > span > em").removeClass("on");
$(this).addClass("on");
})
What should I do?
CodePudding user response:
Try this
$(document).on('click', '.Day', function(){})
CodePudding user response:
Your code is working. You can check by adding alert or console.log inside the click callback function.
$("li > span > em").click(function () {
alert('hello');
$("li > span > em").removeClass("on");
$(this).addClass("on");
})
CodePudding user response:
i think your code is Just fine i can see you've got a typo there. However, you may want to test it out by adding some alerts on click for the both tags.
$("li > span > em").click(function () {
alert('em CLICKED');
$("li > span > em").removeClass("on");
$(this).addClass("on");
});
$("li > span").click(function(){
alert('span CLICKED');
});