Problem
So, I have a h2
and inside the h2
there is a i
and when you click on the h2
, the .inputs
underneath the h2
slideToggle()
's. My problem is that when the h2
is clicked on, I want the i
to rotate 90deg
.
HTML
<h2 class="toggle-inputs">Add Student <i class="fa fa-caret-down" aria-hidden="true"></i></h2>
<form class="inputs" action="server/add/add-student.php" method="post">
<input type="text" name="student-id" placeholder="* Student ID...">
<input type="text" name="firstname" placeholder="* Firstname...">
<input type="text" name="lastname" placeholder="* Lastname...">
<input type="text" name="teacher-firstname" placeholder="* Teacher's Firstname...">
<input type="text" name="teacher-lastname" placeholder="* Teacher's Lastname...">
<span class="spare">Spare Block<input type="checkbox" name="spare"></span>
<button type="submit" name="add-student"><i class="fa fa-plus-circle" aria-hidden="true"></i> Add Student</button>
</form>
JavaScript
// MAIN
function main() {
$(".toggle-inputs").on("click", toggleInputs);
}
// TOGGLE INPUTS
function toggleInputs() {
$(this).parent().find('.inputs').slideToggle("slow", function() {
$(this).children('i').animate({
"transform": "rotate(90deg)",
});
});
}
// LOAD
$(document).ready(main);
You are using Font Awesome. Wouldn't it be easier to simply change the class from fa-caret-down to fa-caret-left/fa-caret-right as required
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.