2

I have a component

<div class="tooltip" onmouseover="{!c.hover}">
    <div >
            <div >
               Test Test Test
            </div>
    </div>
    <div aura:id="textId" class="tooltiptext">
        <div>Test Code</div>
    </div>
</div> </aura:component>

Css applied is

.THIS.tooltip { 
    position: relative;
    display: inline-block; 
}  

.THIS .tooltiptext { 
    visibility: hidden; 
    position: absolute; 
    word-wrap:break-word; 
    text-align: justify; 
}  

.THIS.tooltip:hover .tooltiptext {
    visibility: visible; 
}

now in controller i want to use

hover :(component){ component.find("textId").getElements(); }

error i am getting is

[component.find(...).getElements is not a function]

this error occurs if locker service is enabled.

Is there any way to use component.find("").getElements() on div which is hidden?

8
  • Hi @ManjotSingh, Can you please post the complete code so that folks here can easily try it out and help you where you're stuck? As in which is the div with class name textId , tooltiptext ? Can you please make your question bit more clearer?
    – SE_User
    Commented Dec 26, 2016 at 9:32
  • 1
    @SE_User Thnx for suggestion. I have made changes to code. Commented Dec 26, 2016 at 9:57
  • @ManjotSingh when you are saying "unable to getElements", are you getting an error or what is the behaviour you are seeing? If you could attach a screenshot of log it would help.
    – Praveen
    Commented Dec 26, 2016 at 10:33
  • I am getting error [component.find(...).getElements is not a function] Commented Dec 26, 2016 at 10:46
  • 1
    @ManjotSingh i tried your code it works fine with one correction : hover :function(component){ var divs = component.find("textId").getElements(); console.log(divs)}
    – Praveen
    Commented Dec 26, 2016 at 10:52

3 Answers 3

3

I have done some POC on this component and found out that i was using component.find("") on textId div on init of component. then afterwards whenever i was trying to use component.find(“textId”).getElements() on that div it was giving error because component.find(“textId”) was returning secure component reference. i changed my init method and added my logic onmouseover event now i am able to use component.find(“”).getElements().

3

I've copied your exact same code and everything is working fine with LockerService on. I see 2 potential issues here.

1) You have multiple elements with aura:id="textId" in your markup. This would cause component.find("textId") to return an array of components and calling getElements() on the array will give you the error you report.

2) If it really is only happening with LockerService activated, your call to component.find() is likely returning a SecureComponentRef which doesn't have getElements defined on it, rather than a SecureComponent which does. This typically means you're trying to get a reference to a component that isn't in your current namespace. Are all components and the controller that makes the getElements() call in your namespace?

1
  • 1
    Thnx @Trevor But my problem was different. you can look at my answer. Commented Dec 29, 2016 at 6:11
0

You cannot write your javascript code in the css - you need to to that in the component's controller.

From there you can code your component.find("textId") and handle your css values.

4
  • Actually my question is whether we can use component.find(“”).getElements() to div which is currently hidden. I can add slds-hide/slds-show class to my Div. But problem is when i add slds-hide to my div then try use getElements method it is not working. Commented Dec 26, 2016 at 9:53
  • the div exist so ofcourse you can - check within the page source elements if it exist Commented Dec 26, 2016 at 10:12
  • yes div exist in page source elements. But Problem is as Div is hidden then component.find(“”).getElements() doesnot work. if i change css to visibilty :visible then i am able to use component.find(“”).getElements(). Commented Dec 26, 2016 at 10:31
  • Ok, I think you should refine your question then Commented Dec 26, 2016 at 11:18

You must log in to answer this question.

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