Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7598027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:18:24+00:00 2026-05-30T22:18:24+00:00

In my Rails 3 app I remove a <span> that I use as a

  • 0

In my Rails 3 app I remove a <span> that I use as a placeholder on input with jQuery. If I submit the form and I have errors, the form reloads and the errors are shown. However, for the fields where there were errors, the <span> won’t clear on input because the <span> is no longer within the <div> containing the input. (This is due to the field_with_errors <div> added from the error.) How can I work around this and still remove the <span> despite field_with_errors?

Here’s my jQuery:

// placeholder label for text
$(function() {
    $("span.holder + input").keyup(function() {
        if($(this).val().length) {
            $(this).prev('span.holder').hide();
        } else {
            $(this).prev('span.holder').show();
        }
    });
    $("span.holder").click(function() {
        $(this).next().focus();
    });
});

My html with field_with_errors (jQuery doesn’t work):

<div class="holds email">
  <span class="holder">Email</span>
  <div class="field_with_errors">
    <input autocomplete="off" id="user_email" name="user[email]" size="38" type="text" value="">
  </div>
</div>

My html without field_with_errors (jQuery works):

<div class="holdsname">
  <span class="holder">Last name</span>
  <input autocomplete="off" class="inner" id="user_profile_attributes_last_name" name="user[profile_attributes][last_name]" size="18" type="text">
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:18:26+00:00Added an answer on May 30, 2026 at 10:18 pm

    What about

    $('.holds').find('input').keyup(function ()
    {
        if ($(this).val().length)
        {
            $(this).closest('.holds').find('.holder').hide();
        }
        else
        {
            $(this).closest('.holds').find('.holder').show();
        }
    });
    
    $('span.holder').click(function ()
    {
        $(this).parent().find('input').focus();
    });
    

    jsFiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rails app that I've been testing on heroku, it's a simple
I have recently been advised that for my current rails app relationships I should
I'm trying to create a multi-level ajax form on my rails app that can
I have a Rails 3 app that is trying to perform some controller action
in my rails 3 app I use devise. For the password reset form I
I have a rails app, that is setup with the default test unit, how
I have built a ruby on rails app that lets users track their workouts.
I have a simple Rails 3.1.rc6 app that I'm using to try to test
My Basic Goal A Rails app that can load new content via Ajax while
I have a fairly complex Rails app built on top of Twitter's API, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.