Getting the next textbox using the next() function in jquery -


i trying write jquery code value of next textbox of class "in". code have here isn't working, value undefined. think using next() function incorrectly not sure, have input?

<!doctype html> <html>  <body> <input type="text" class="mm" /> <br> <input type="text" class="in" />    $(document).ready(function() {     $("input").focus(function() {          var value = $(this).next(".in").val();         if (value) {             alert(value);         }      }); });       </script>  </body> </html> 

your example you've given html works. can see here: http://jsfiddle.net/jfriend00/rgsdq/. based on comments, sounds want first sibling has class "in" whether it's next sibling or not. .next() examines next sibling. if want first sibling has class "in" if it's not next sibling, can either of these:

$(this).nextall(".in").first().val();           // next sibling class ".in" $(this).parent().find(".in").first().val();     // next child of parent class ".in" 

you can see first of these 2 options working here: http://jsfiddle.net/jfriend00/4vwan/


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -