Javascript-форум (https://javascript.ru/forum/)
-   Ваши сайты и скрипты (https://javascript.ru/forum/project/)
-   -   Не работает .focus() (https://javascript.ru/forum/project/50205-ne-rabotaet-focus.html)

vommer 16.09.2014 17:59

Не работает .focus()
 
День добрый

Есть такая структура:

<div class="one"><input value="" placeholder="Name" class="control" type="text"></div>

- при клике <div class="one"> меняется на <div class="two"> и курсор должен встать в этот input, делаю так: $("input[placeholder='Name']").focus(); . Но не работает, при этом $("input[placeholder='Name']").fadeout(); работает отлично

*inputов на странице много

Подскажите, что может мешать/куда копать

Спасибо

ksa 17.09.2014 09:18

Цитата:

Сообщение от vommer
Подскажите, что может мешать/куда копать

Как вариант...

<!DOCTYPE html>
<html>
<head>
<script src='http://code.jquery.com/jquery-latest.js'></script>
<!--
<link rel='stylesheet type=text/css href=tmp.css' />
-->
<style type='text/css'>
div {
	padding: 20px;
}
.one {
	background-color: green;
}
.two {
	background-color: yellow;
}
</style>
<script type='text/javascript'>
$(function(){
	$('.one').click(function (){
		$(this).removeClass('one');
		$(this).addClass('two');
		$(this).find('input[placeholder="Name"]').get(0).focus();
	});
}); 
</script>
</head>
<body>
<div class="one">
	<input value="" placeholder="Name" class="control" type="text" />
</div>
</body>
</html>
</html>


Часовой пояс GMT +3, время: 14:47.