0

I have an anchor tag in the component where i need to get the id of the anchor tag to my JavaScript controller.

Component

<a class="notifLinkTwo" data-toggle="dropdown" aria-haspopup="true" id="notificationDropdownId" aria-expanded="false" onclick="{!c.clickButtonTwo}">

Controller

clickButtonTwo : function(component, event, helper){
    var x = document.getElementById("notificationDropdownId");
         alert('x: '+ x);
}

Currently I am not getting the value for the x in the alert.

1
  • id's are not supported, considering that these are changed on runtime, you will have to use aura:id's and component.find() to get the matching element.
    – glls
    Mar 12, 2020 at 11:19

1 Answer 1

0

As per the DOM Access contaiment Guidelines for aura components

Component:

<a class="notifLinkTwo" data-toggle="dropdown" aria-haspopup="true" aura:id="notificationDropdownId" aria-expanded="false" onclick="{!c.clickButtonTwo}">

CONTROLLER

({ clickButtonTwo : function(cmp, event, helper) {
        // access the DOM in c:domLocker
        console.log("notification: ", cmp.find("notificationDropdownId").getElement());
    }
})

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .