I am using Data attributes to get an element in jQuery as below
<a class="toggleArrow">Toggle Me</a>
<span class="arrow collapse" data-target="trgt1">
<i class=fa fa-arrow-right""></i>
</span>
<span class="arrow collapse" data-target="trgt2">
<i class=fa fa-arrow-left""></i>
</span>
JQuery is
$("a.toggleArrow").off().on("click", function () {
$("span.arrow").each(function () {
var dataTarget = $(this).data("target");
if (dataTarget == "tgrt1") {
dataTarget.toggleClass("collapse expand");
}
});
});
Can we use this way but it does not seem to work?