Edited to clarify requirements
I am trying to simulate a click in a div through browser scripting. The div I am working on is :
<div id="myid" class="myclass" hidefocus="true" aria-label="Message Body" g_editable="true" role="textbox" aria-multiline="true" contenteditable="true" tabindex="1">hello how</div>
The problem is that I am able to trigger a focus but I wanted a drop down to appear that only appears after a click has been made. The focus is occuring but I cannot simulate the click. My requirement is to use Javascript alone. What I have tried:
document.getElementById("id1").dispatchEvent(new Event("click"));
document.getElementById(":16b").focus();
document.getElementById(":16b").selectionStart = 5;
var el = document.getElementById("editable");
var range = document.createRange();
var sel = window.getSelection();
range.setStart(el.childNodes[0], 5); //edit the offset here...e.g 5 offsets cursor
by 5 char
sel.removeAllRanges();
sel.addRange(range);
el.focus();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.