I am using the code below which is part of Bootstrap Framework.
My goal is to focus the input if click on <a>name</a>
via Jquery's click/focus functionality. I already know its about the data-toggle="dropdown"
attribute in the a
link make it doesnt work. I am not really experienced. Hopefully anybody got some help for me!
<html>
<body>
<li class="dropdown">
<a class="dropdown-toggle" id="dLabel" role="button" data-toggle="dropdown" data-target="#" href="#"><i class="icon-user"></i> name </a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
<li>
<form ...>
<input type="text" id="4711" />
</form>
</li>
</ul>
</li>
</body>
</html>
<script>
$('#dLabel').click(function() {
$('#4711').focus();
});
</script>
You should put your code in document ready handler:
{for bootstrap, you could use a timeout as a simple workaround}
SEE DEMO
$(function () {
$('#dLabel').click(function () {
setTimeout(function(){$('#login').focus();},0);
});
$('.dropdown input[type=text]').click(function(e){
e.stopPropagation();
});
});
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