I have a form with inputs and and div container outside of form with help text for each input.
<form>
<input id="name" />
<input id="email" />
<input id="pass" />
</form>
<div class="help-container">
<p class="help-name"></p>
<p class="help-email"></p>
<p class="help-pass"></p>
</div>
Now the .help-container is initially hidden with { display: none; } as well as each child p.
The jQuery I’m having trouble with is:
$("form").find("input").focus(function(){
var parent = $(this).attr("id");
$(this).closest("form").next(".help-container").show();
})
1) This does not work. Why?
$("form").find("input").focus(function(){
var parent = $(this).attr("id");
$(this).closest("form").next(".help-container").show();
$(".help-container").children("p").hide();
$(".help-container").children("p").find(".help-" + parent).show();
})
2) This does not work. Why?
Here are your issues
You need to change it to this
http://jsfiddle.net/vjUme/