code_junkie

How do I hide a div based on empty input fields within it?

Nov 12th, 2011
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. <div class="details"></div>
  2.  
  3. //hide the all of the element class details
  4. $(".details").each(function (i) {
  5. if ($('input[name$=surname]:empty',this).length == 1) {
  6. $(this).hide();
  7. } else {
  8. $(this).show();
  9. }
  10. });
  11.  
  12. <div class="details">
  13. <input type="text" name="surname" />
  14. </div>
  15.  
  16. <script type="text/javascript">
  17. $(".details input[@value='']").parents(".details").hide();
  18. </script>
  19.  
  20. $("div.details input").each(function () {
  21. if (this.value == "")
  22. $(this).parents("div.details").eq(1).hide();
  23. else
  24. $(this).parents("div.details").eq(1).show();
  25. });
  26.  
  27. $("div.details input[name$=surname]").each(function () { /* etc... */
  28.  
  29. //hide the all of the element class details
  30. $(".details").each(function (i) {
  31. if ($('input[name$=surname][value=""]',this).length == 1) {
  32. $(this).hide();
  33. console.log('hiding');
  34. } else {
  35. $(this).show();
  36. console.log('showing');
  37. }
  38. });
Add Comment
Please, Sign In to add comment