0

I want to change the focus of the element in client side controller. I have below div element in component.

<div id="globalId" aura>
    {!v.body}    
</div> 

I want to change the focus by using below jQuery function but it is not working.$("#globalId").hide() is working but not the below function.

$("#globalId").focus();
5
  • Could anyone please advise how to get this done
    – Mikey
    Commented Jun 9, 2015 at 17:20
  • 1
  • @KeithC Thanks for the quick reply.It is not working in Salesforce1 app.It is taking me to Salesforce one homepage and URL displays cs12.lightning.force.com/one/one.app#globalId.
    – Mikey
    Commented Jun 9, 2015 at 17:45
  • For the scrolling to work its a named anchor you would need to add <a name="globalId"/>. But if the Salesforce 1 app is using the anchor name to switch pages that won't work. Someone who knows more about Salesforce 1 apps will hopefully be able to answer.
    – Keith C
    Commented Jun 9, 2015 at 19:41
  • What exactly are you trying to accomplish? Divs are not normally focusable unless they have contenteditable enabled. Is this an editable div? If not what is the desired end result? If you just want to scroll it into view, that can be done other ways.
    – Charles T
    Commented Jul 2, 2016 at 5:45

1 Answer 1

2

Please do not make any changes to the DOM in javascript controllers. This functionality is not supported, may lead to race conditions, and will cause trouble in the security review. Make changes to the aura component objects, and let the renderer update the DOM. If you want to make DOM changes yourself, do this in a renderer, not in a controller, in order to ensure that your update will be the final update and will not be overwritten by the default renderer.

You must log in to answer this question.

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