I tried
$(":input:not(input[type=button],input[type=submit],button):visible:first")
but it doesn't find anything.
What is my mistake?
UPD: I execute this on $(document).load()
<script type="text/javascript">
$(window).load(function () {
var aspForm = $("form#aspnetForm");
var firstInput = $(":input:not(input[type=button],input[type=submit],button):visible:first", aspForm);
firstInput.focus();
});
</script>
and in the debug I can see that firstInput is empty.
UPD2: I'm in ASP.NET page running under Sharepoint.
I've found so far that for some elements it does find them (for fixed ones) and for some don't. :(
This is my summary of the above and works perfectly for me. Thanks for the info!
You may try below code...
Why not just target the ones you want (demo)?
Edit
Or use jQuery :input selector to filter form descendants.
The JQuery code is fine. You must execute in the ready handler not in the window load event.
Update
I tried with the example of Karim79(thanks for the example) and it works fine: http://jsfiddle.net/2sMfU/
This is an improvement over @Mottie's answer because as of jQuery 1.5.2
:text
selectsinput
elements that have no specifiedtype
attribute (in which casetype="text"
is implied):Here is my solution. The code should be easy enough to follow but here is the idea:
The code:
Then simply call focusFirst with your parent element or selector.
Selector:
Element: