javascript - Focus textarea on mobile from click event using jQuery .trigger() -


alrighty, i'm stuck.

i'm trying desperately focus on text area programmatically javascript (jquery) on mobile. did research, , learned way bring keyboard .focus() use click event. made click event. , works when click on element, except need trigger touchhold on different element. naturally, tried .trigger() , .triggerhandler() on element. neither of things work.

tldr; need able hold on element list, , after time, div slide down textarea , textarea gets focus (with keyboard).

any appreciated!

here code:

<div class="quicknote" data-id="0">     <span>new note</span>     <div class="name"></div>     <textarea class="text"></textarea>     <div class="toolbar">         <div class="left cancel">cancel</div>         <div class="right finish">finish</div>     </div> </div> 

jquery

jquery(document).ready(function($) {     var holdthresh = 800;     $(".row").on("touchstart", function(e) {     var id = $(this).attr("data-id");     var name = $(this).html();     $(this).addclass("down");     var timer = settimeout(function() {         $(".quicknote").attr("data-id", id);         $(".quicknote .name").html(name);         $(".quicknote").addclass("open");         $(".quicknote").trigger("click");         e.preventdefault();     }, holdthresh);      $(this).one("touchend touchmove", function(event) {         $(this).removeclass("down");         cleartimeout(timer);     })      $(".quicknote .cancel").on("touchstart", function() {         $(".quicknote").removeclass("open");     })      $(".quicknote").click(function(event) {         $("textarea").focus();         event.preventdefault();         event.stoppropogation();     }) }); 

i figured out! finds this, here updated jquery:

$(".row").on("touchstart", function(e) {     var id = $(this).attr("data-id");     var name = $(this).html();     var go = true;     var focus = false;      $(this).addclass("down");      var timer = settimeout(function() {         go = false;           $(".quicknote").attr("data-id", id);         $(".quicknote .name").html(name);         $(".note").val("");          $(".quicknote, .overlay").addclass("open");         focus = true;          e.preventdefault();     }, holdthresh);      $(this).one("touchmove", function(event) {         go = false;         $(this).removeclass("down");         cleartimeout(timer);     });      $(this).one("touchend", function() {         if (go) window.location = "view.php?id=" + id;         else {             if (focus) {                 $(".note").focus();                 focus = false;             }             $(this).removeclass("down");             cleartimeout(timer);         }     }) }) 

i'm not sure why works, instead of triggering click on third element focus on textarea, set flag "var focus", , based on conditions, able focus textarea touchend event. hope helps someone! :)


Comments