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

  • Home
  • SEARCH
  • 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 7507875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:34:26+00:00 2026-05-29T22:34:26+00:00

Am trying to select the element after the element am working and retrieve its

  • 0

Am trying to select the element after the element am working and retrieve its class, but i keep the undefined error
this is the html

<div class="clearfix">
                    <input type="text" name="username" placeholder="Username" /><span class="form-validation-status"></span>
               </div>

And this is the javascript

$(document).ready(function() {
    var username_field = $("input[name='username']");
    var email_field = $("#_email");
   var host_url = "http://localhost/ur/";
        //Check if the username is already in use
        username_field.blur(function() {
            var _username = username_field.val();
            var uri = host_url+"accounts/signup/is_username_exist/"+_username;
            $.ajax({ 
                url:uri,
                type:'GET',
                dataType:'json',
                success:function(data) {
                                   var test = $(this).closest("span").attr("class");
                                   alert(test);
                } 
            });
});

Its keeps alerting as undefined what am doing wrong?

  • 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-29T22:34:27+00:00Added an answer on May 29, 2026 at 10:34 pm

    You want to use next() not closest()

    And $(this) in your success handler refers to data, you need to define the variable earlier in order to fetch it there.

    var $theSpan = $("input[name='username']").next();
    alert($theSpan.attr('class'));
    

    Should do it.

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

Sidebar

Related Questions

I'm trying to select an select element by name I found this thread showing
I'm trying to select an element based on its href within a table of
This error in Firebug: missing ) after argument list [Break On This Error] $('select
I'm trying to select the first h1 inside a div with a class called
I'm trying to select an element from my webpage... I have inserted a control
I'm trying to select the text from the name attribute of the anchor element
I'm trying to style all <select> elements that are a descendant of a <div>
Trying to select anchor tags that are a descendants of a div with a
after an hour of trying to find a solution, I give up (temporarily). this.selectedIndex
I have been trying to get simple YES/NO radio buttons list working but facing

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.