Please help.jquery addClass() che non funziona con event.target
Perché jquery addClass()
non funziona con event.target
? Ho creato un codice e si suppone che aggiunga classe alla destinazione quando si fa clic, ma non funziona, e dice, e.target.addClass
non è una funzione.
CODICE:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Class Test</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<style>
.big {
font-size: 5em;
}
.small {
font-size: 1em;
}
</style>
</head>
<body>
<p>This is the text</p>
<script>
$(function() {
$("p").click(function(e) {
$("a").removeClass("big").addClass("small");
$("this").addClass("big"); //This doesn't work
e.target.addClass("big"); //nor this one
});
});
</script>
</body>
</html>
Wow. Funziona! Perché? – qtgye
@ user3540736 avevo dato alcune spiegazioni riguardo a ciò nella mia risposta .. :) –
Ora è così chiaro per me. Molte grazie! :) – qtgye