KTDrawer does not have getTargetElement like ktmodal
modal.on("show", function () {
console.log(modal.getTargetElement());
}); Hi
Sorry about that. getRelatedTarget() returns null when used inside the show event because the related target is set after that event fires. We’ve noted this for a future release.
Workaround 1 – use the shown event
By the time shown runs, the related target is available:
drawer.on("shown", function () {
console.log(drawer.getRelatedTarget()); // returns the element that triggered the drawer
}); let lastToggleElement = null;
document.body.addEventListener("click", function(e) {
const toggle = e.target.closest("[data-kt-drawer-toggle]");
if (toggle) lastToggleElement = toggle;
}, true);
drawer.on("show", function () {
const trigger = lastToggleElement || drawer.getRelatedTarget();
console.log(trigger);
}); Hi
KTDrawer doesn’t expose getTargetElement(), but it does expose getRelatedTarget(), which returns the element that triggered the drawer (the same idea as KTModal’s target). You can use it like this:
drawer.on("show", function () { console.log(drawer.getRelatedTarget());}); Hi
Sorry for the earlier mix-up. There’s no update yet. KTDrawer still doesn’t expose a getTargetElement() method like KTModal. We’ve noted the request and will consider adding it in a future release. I appreciate your patience.