jQuery - search for previous selector relative to current
Posted
by Thomas Slater
on Stack Overflow
See other posts from Stack Overflow
or by Thomas Slater
Published on 2010-06-13T23:53:03Z
Indexed on
2010/06/14
0:02 UTC
Read the original article
Hit count: 219
jQuery
|jquery-selectors
I have a form with 3 sections in it. Each section has a dedicated div for fairly long contextual help messages regarding the input that has focus.
My question is, if I give each of these help divs a class of "form-tip" and each input that has a tip the class "has-tip", how can I get the tip to always show up in the previous "form-tip" div?
Something like:
$('.has-tip').each(focus(function() {
var tip = $(this).attr('title');
// Find most recent $('.form-tip') in the DOM and populate it with tip
}));
I hope that makes sense... Thanks for any help.
© Stack Overflow or respective owner