I'm creating a List that has one or more buttonIcons in the end.I'm creating these buttons dynamically with $A.createComponent
.
While clicking the button,I need to find which button is clicked and then finding its position with getBoundingClientRect()
.
How can I do it?
I tried event.getSource()
,event.currentTarget
& event.target
.
Nothing helped!
Or Is there any ways to find the position of a element in lightning.
(I need to show a popup relative to the button's position,can't use lightning:helptext)
2 Answers
- First find the body of the parent component of the dynamically created components.
- Then find the button and
getBoundingClientRect
Refer this QA,
`
findButton : function(cmp) {
var parentElement = cmp.find("parent").get("v.body");
console.log("child 1",parentElement[buttonIndex].find("buttonId").getBoundingClientRect());
}
`
Please Check the below code, It will help you to find which button you clicked.Can you please add your code snippets.
<aura:component>
<aura:attribute name="whichButton" type="String" />
<p>You clicked: {!v.whichButton}</p>
<ui:button aura:id="button1" label="Click me" press="{!c.nameThatButton}"/>
<ui:button aura:id="button2" label="Click me too" press="
{!c.nameThatButton}"/>
</aura:component>
Javascript:
({
nameThatButton : function(cmp, event, helper) {
var whichOne = event.getSource().getLocalId();
console.log(whichOne);
cmp.set("v.whichButton", whichOne); } })
event.getSource().getElement()
too?event.getSource().getElement()
is not a function.