JQuery creates a text input element and is added to the "Field Focus" form in Firefox does not work

I have the following code (see below) that focuses a field on pasted text input. But this does not work in Firefox. Therefore, I cannot print text in Firefox.

$('<input/>').attr({ type: 'text', id: 'test', name: 'test' }).appendTo('#form'); 

Is there any fix for this?

Thanks in advance!

-

Correction to my question

I found out that the problem is caused

$(selector).sortable().disableSelection()

The only permission I have right now is not to call

//disableSelection()

Any other suggestions are welcome.

+8
jquery
source share
3 answers

try focus

 $('<input/>').attr({ type: 'text', id: 'test', name: 'test'}).appendTo('#form'); $('#test').focus(function(e) { alert('Focus'); }); 
+1
source share

Try the code below -

 $('<input/>').attr({ type: 'text', id: 'test', name: 'test', autofocus: 'true' }).appendTo('#form'); 
0
source share

This works great with Firefox 45:

 <!doctype html> <html> <head> <meta charset="UTF-8"> <title>Javascript/jQuery Tests</title> <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.3.js"></script> <script type="text/javascript"> $(document).ready(function(e) { $('<input/>').attr({ type: 'text', id: 'test', name: 'test' }).appendTo('#myForm').focus(); }); </script> </head> <body> <form name="myForm" id="myForm" method="post"></form> </body> </html> 
0
source share

All Articles