Actually the example you gave for focusing on this site works just fine, as long as you’re not focused in the console. The reason that’s not working is simply because it’s not stealing focus from the dev console. If you run the following code in your console and then quickly click in your browser window after, you will see it focus the search box:
setTimeout(function() { $('input[name="q"]').focus() }, 3000);
As for your other one, the one thing that has given me trouble in the past is order of events. You cannot call focus() on an element that hasn’t been attached to the DOM. Has the element you are trying to focus already been attached to the DOM?
Related Posts:
- What does [object Object] mean? (JavaScript)
- Why does my JavaScript code receive a “No ‘Access-Control-Allow-Origin’ header is present on the requested resource” error, while Postman does not?
- How can I get the ID of an element using jQuery?
- How to show loading spinner in jQuery?
- speedtest.net api
- jQuery Ajax error handling, show custom exception messages
- How to write jquery If else statement?
- How to break out of jQuery each loop?
- jQuery – Add ID instead of Class
- Can Twitter Bootstrap alerts fade in as well as out?
- jQuery Scroll to bottom of page/iframe
- jQuery – Illegal invocation
- How to call a webservice method from an html page [javascript] with out refresh the page
- Random background images CSS3
- ajax stopped working when not logged in?
- Is there a way to enable Cross-Origin Resource Sharing for WordPress’ ajaxurl?
- How to get attachment id as soon as it is uploaded through media uploader in jquery?
- Using ‘$’ instead of ‘jQuery’ in WordPress
- AJAX call returns 0
- jQuery and AJAX Not working with Select Form Element
- Force wp_enqueue_scripts to the HEADER?
- Is it possible to get the logged in username in a jquery script?
- Gravity Forms loading jquery
- Extend 3.5 media uploader plugin to change button name
- WordPress and jQuery [closed]
- Any good lightbox-like option that works in WP 3.2.1?
- Javascript included but alert() function not working
- Adding fields to the media uploader with jquery listeners
- Bind to WPSetAsThumbnail
- How do I activate jQuery/script on demand?
- How to delete post attachments when jQuery is used with a click event on the delete link
- Ajax pagination works only first and third time
- How to properly add Bootstrap and JQuery Javascripts?
- Using multiple versions of jQuery while still calling it like WP likes
- adding google event tracking to links in posts
- how can I make $ work in wordpress for jQuery?
- Override default jquery ui library with newer version
- Can I make simple global tooltips in WordPress?
- WordPress Jquery Confliction with Plugin
- Is there a restriction in WP on the use of jQuery load function?
- Periodically getting jQuery “…. is not a function” errors [closed]
- Gutenberg Filtering Metaboxes by Post Format
- Unwanted content in website title
- HTML editor accessing quicktag buttons
- Error when posting comment form: The error is TypeError: e[h] is not a function
- show element on page load from external url only [closed]
- How to use datepicker.min.js?
- Exclude some scripts from removing unique scripts from head function
- Using Javascript to detect keypress event in text editor
- videopress videos are not displayed when loading the content with ajax in a lightbox
- Bypass nonce value while trashing a post
- How to enqueue jquery in admin and why is it not already there?
- Call a javascript function from another file
- Adding JS to one page
- Set TRUE or FALSE based on a wp_localize_script option value
- Display posts from another site using REST API in an asynchronous manner
- Simplest ajax form not working when it should
- How do I include javascript/jquery image resizing with wordpress?
- Changing WordPress URL breaks some jquery functions
- Extend the twentyten dropdown menu with jQuery with a delay onmouseout
- Loading a newer version of jQuery within WordPress
- Notice-Updated div moving around unprompted
- How to display comments length
- How to change the text of the “You are about to permanently delete these items…” alert message when deleting media from the media library?
- get value from selected input
- Can’t execute jQuery before my script
- Admin Ajax is returning 0 and not Insert data
- Multiple Media uploader output to input
- extra code in – blank jquery function
- Using WP functions inside javascript
- How to add external remote JS source to Gravity Forms?
- Why is ajax working on one server and not the next?
- Connect Agile Carousel to WordPress AJAX
- How to add shortcode to show/hide press releases?
- Calling multiple scripts using wp_enqueue_script
- jQuery forms & updating info
- How to use script in WordPress installation?
- Defer Parsing of Scripts
- Orderby post__in Not Working Correctly?
- JavaScript code do not works on online server
- File not enqueueing
- Enqueue script, taking no effect [closed]
- How to add jQuery script?
- Displaying contents of a tab
- Local version of jquery not working right
- In the Edit Post page how do I modify with jQuery the status select list?
- Variable not being returned from Ajax Javascript (though javascript receives it)
- Object [object Object] has no method ‘slides’
- Append jquery script for each [partners] shortcode with specified values
- Infinite scroll page number [duplicate]
- Thumbnail remove width & height function
- Change jQuery(document).ready to $.delegate in wordpress
- How to install Lavalamp jQuery effect in wordpress [duplicate]
- How to Run a jQuery Script after a Javascript Script has Finished in WordPress
- Using jQuery to override the content of a div [closed]
- Hook with jquery script is not working in wp-admin [closed]
- Custom JQuery script in page template won’t work [duplicate]
- jQuery functions work in console, but not live
- Uncaught TypeError: number is not a function [closed]
- Cannot get jQuery to work in WordPress [duplicate]