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. :(
Why not just target the ones you want (demo)?
$('form').find('input[type=text],textarea,select').filter(':visible:first');
Edit
Or use jQuery :input selector to filter form descendants.
$('form').find('*').filter(':input:visible:first');
The JQuery code is fine. You must execute in the ready handler not in the window load event.
<script type="text/javascript">
$(function(){
var aspForm = $("form#aspnetForm");
var firstInput = $(":input:not(input[type=button],input[type=submit],button):visible:first", aspForm);
firstInput.focus();
});
</script>
Update
I tried with the example of Karim79(thanks for the example) and it works fine: http://jsfiddle.net/2sMfU/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With