0

I am trying to focus on input window but its giving error :enter image description here

<div class="intercom-conversation-footer" data-
    reactid=".2.1.$=1$conversation.2"><div class="intercom-composer" data-
    reactid=".2.1.$=1$conversation.2.0"><pre data-
    reactid=".2.1.$=1$conversation.2.0.0"><span data-
    reactid=".2.1.$=1$conversation.2.0.0.0">write something</span><br data-
    reactid=".2.1.$=1$conversation.2.0.0.1"></pre><textarea placeholder="Write 
    a reply..." data-reactid=".2.1.$=1$conversation.2.0.1"> </textarea><span
     data-reactid=".2.1.$=1$conversation.2.0.2"></span><button class="intercom-
    composer-emoji-button" data-reactid=".2.1.$=1$conversation.2.0.5"></button>
    <button class="intercom-composer-send-button" data-
    reactid=".2.1.$=1$conversation.2.0.7"></button></div></div>

i want to focus on this how i can ?

my code is :

var message = document.createEvent("TextEvent");  
message.initTextEvent ("textInput", true, true, window, "Hello", 0, "en-US");
document.getElementById(".2.1.$=1$conversation.2.0.0.0").focus();

but its giving error :

VM20681:1 Uncaught TypeError: Cannot read property 'focus' of null(…)
  • 5
    `data-reactid` and `id` are two separate properties! Those elements currently do not have any id at all. – arkascha Oct 13 '16 at 14:12
  • 1
    You will need to use something like http://stackoverflow.com/questions/9496427/get-elements-by-attribute-when-queryselectorall-is-not-available-without-using-l – BrTkCa Oct 13 '16 at 14:13
  • @arkascha Thanks then how i can focus on that using data-reactid ? –  Oct 13 '16 at 14:14
  • You shouldn't, though it is possible to select by property name. Reason is that it is 1. really ineffective and 2. not robust, since those data attributes look pretty dynamic to me. Instead check if you cannot define an id or a class for the element you want to select. And since you tagged this question with `jquery` take advantage of the much more powerful selectors that library offers compared to the plain vanilla ones you currently use. – arkascha Oct 13 '16 at 14:18

2 Answers2

1

You don't have id, but only data-reactid property. So, you can use some like as: document.querySelector("span[data-reactid='.2.1.$=1$conversation.2.0.0.0']").focus();

0

You may use jQuery's attribute selector

$('[data-reactid=".2.1.$=1$conversation.2.0"]').focus();
ahmetertem
  • 242
  • 6
  • 14