I try to add an "active" class to a 'a' tag on a 'div' using jquery.
When I put Alert() instead of addclass(), it finds the target (#active0).
But when I insert addclass() or anything else , nothing happens.
I'm new on Jquery (and on Forums :) ) and surely forgot something or don't understand a concept.
Question:
How could I do to see the .active class appears on my html to activate the .active class css properties on the web page?
Thank you all in advance for your help and advice.
You could find code bellow.
$(document).ready(function(){
$("document").on("click","#active0", function () {
$(this).addclass("active");
});
});
.folder{
display: flex;
justify-content: center;
align-items: center;
width: 130px;
height:30px;
}
.folder a{
display: flex;
justify-content: center;
align-items: center;
text-decoration: none;
color: rgba(1, 113, 185, 0.8);
width: 130px;
border-radius: 20px;
border:1px solid rgba(1, 113, 185, 0.8);
background-color: white;
transition-duration:0.6s;
}
.folder a.active{
border:3px solid red !important;
}
<hmtl>
<body>
<div id="parent2" class="folder">
<a id="active2" href="#">test</a>
</div>
<div id="parent1" class="folder">
<a id="active1" href="#">test1</a>
</div>
<div id="parent" class="folder">
<a id="active0" href="#">test2</a>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</body>
</hmtl>
question from:
https://stackoverflow.com/questions/65900620/jquery-alert-works-but-not-addclass-or-anything-else 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…