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 7489953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:27:15+00:00 2026-05-29T15:27:15+00:00

Heyo. This is my first stack overflow post because I am stumped and not

  • 0

Heyo. This is my first stack overflow post because I am stumped and not finding many people who are trying to accomplish the same thing. I’ve tried using jquery .before(), .after(), and .wrap() to resolve this. I was initially using css :before and :after pseudo-elements, but as that won’t work for legacy browsers, I’ve decided to use jquery.

I already have several forms on several pages with validation working. The error messages vary in length. We were using a static, one size background image on the default span element, so content was bleeding out on longer error messages. I built a flexible rounded corner series of nested divs to allow the error box to grow or shrink dynamically. The html I want to output is:

<div class="errorWrap">
<div class="errorTop"><span></span></div>
<div class="errorContent">
    <span class="error">This is an error</span>
</div>
<div class="errorBottom"><span></span></div>
</div>

Here’s an example of a solution I tried, but I’m still pretty new to javascript.

 $('.error').before('<div class="errorWrap"><div class="errorTop"><span></span></div><div class="errorContent">');
 $('.error').after('</div><div class="errorBottom"><span></span></div></div>');

Correct me if I’m wrong, but I think that I have the right idea with the jquery. But it’s just kind of sitting there, not in any function being called. So I imagine that since the code isn’t re-executing, it just doesn’t show up. Is there an appropriate function to wrap this in? I’m certain I’m just not attacking this from the right direction. Any help is super appreciated.

  • 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-29T15:27:17+00:00Added an answer on May 29, 2026 at 3:27 pm

    I ended up fixing this problem on my own using jquery to create the div and it’s nesting on pageload, the divs are generated with an error class that gives display:none. A custom errorPlacement function nests the error in the correct div. Then I used a custom validator highlight function to remove the class that hides the element. Then I used the unhighlight function to re-add the class to re-hide the div.

    $(function() {
        //Generate the elements and assign attributes
        var errorWrap = document.createElement('div');
        $(errorWrap).addClass('errorWrap hideError');
        var errorTop = document.createElement('div');
        $(errorTop).addClass('errorTop');
        var topSpan = document.createElement('span');
        var errorContent = document.createElement('div');
        $(errorContent).addClass('errorContent');
        var errorBottom = document.createElement('div');
        $(errorBottom).addClass('errorBottom');
        var bottomSpan = document.createElement('span');
    
        //Place the elements directly after each dd element
        $("dl > dd").append(errorWrap);
        $("div.errorWrap").append(errorTop)
            .append(errorContent)
            .append(errorBottom);
        $("div.errorTop").append(topSpan);
        $("div.errorBottom").append(bottomSpan);
    
        //Add custom validator defaults
        $.validator.setDefaults({
            errorPlacement: function(error, element) {
                $(element).nextAll('.errorWrap').children('.errorContent').append(error);
            },
            highlight: function(element) {
                $(element).nextAll('.errorWrap').removeClass('hideError');
            },
            unhighlight: function(element) {
                $(element).nextAll('.errorWrap').addClass('hideError');
            }
        });
    
    }
    

    Although I’m sure this could have been done more shorthand, I really like this technique because I didn’t have to update any of my pages that contained forms to get it to work. All of the nested divs are dynamically created by javascript, so I can include a global file to any page with forms and it will just work. Thanks for all who offered suggestions.

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

Sidebar

Related Questions

Heyo, My class at college has us writing programs in assembly. I have never
Heyo, I'm currently working on a project where I need to place the camera
Heyo, I'm using a 2000px width image as a background for a 960px width
Heyo, Odd question... is it possible/ ok. To use a combination of SESSION variables
Heyo! I am writing an application in Qt/C++ that creates connections between peers. The
Heyo, Just started writing an assembler for the imaginary computer my class is creating
So I've just started playing around with Django and I decided to give it

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.