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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:46:05+00:00 2026-06-09T13:46:05+00:00

I have some code that’s finding the ‘title’ attribute from each child in a

  • 0

I have some code that’s finding the ‘title’ attribute from each child in a form.

It pulls out the title just correctly when I run ‘console.log(‘title’). But when i try to apply the code to insert a label before the inner div of the fieldset, it just adds the same title (‘About Me’) to each of them.

html

<form action="#" method="post">
    <fieldset title="About Me">
        <!-- Going to convert legends to h4 // can choose the header style element? -->
        <div>
            <label for="name">Text Input:</label>
            <input type="text" name="name" id="name" value="" tabindex="1" />
        </div>
    </fieldset>

    <fieldset title="Radio Button Choice">
        <div>

            <label for="radio-choice-1">Choice 1</label>
            <input type="radio" name="radio-choice-1" id="radio-choice-1" tabindex="2" value="choice-1" />

            <label for="radio-choice-2">Choice 2</label>
            <input type="radio" name="radio-choice-2" id="radio-choice-2" tabindex="3" value="choice-2" />
        </div>
    </fieldset>

    <fieldset>
        <div>
            <label for="select-choice">Select Dropdown Choice:</label>
            <select name="select-choice" id="select-choice">
                <option value="Choice 1">Choice 1</option>
                <option value="Choice 2">Choice 2</option>
                <option value="Choice 3">Choice 3</option>
            </select>
        </div>
    </fieldset>
</form>

jQ

kids = this.element.children('fieldset');
 kids.each(function(){ //function to do something to each of the child fieldset elements
 console.log(this);

 title = $(this).attr('title');

console.log(title); //this logs each title fine, or 'undefined' where there isn't one
$("<legend>" + title + "</legend>").insertBefore('div:first-child')
//that's where I'm just getting 'About me', on every damn one....
 });

Can anyone spot where I’m being a fool? Thanks.

  • 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-06-09T13:46:06+00:00Added an answer on June 9, 2026 at 1:46 pm

    Your selector is too generic – div:first-child will select all of the divs. Look for the div that is a descendant of this fieldset.

    // Based on your existing code
    $("<legend>" + title + "</legend>").insertBefore($(this).find('div:first-child'));
    
    // Slightly cleaner
     $(this).prepend("<legend>" + title + "</legend>")
    

    Also, make sure you make title a local variable with the var keyword:

    var title = $(this).attr('title');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that runs a model in a loop. Each iteration of
I have some code that creates some span tags and each span has its
I have some code that reads from a file, and outputs the Fibonacchi numbers.
I have some code that downloads a file from the internet located here: http://www.amsat.org/amsat/ftp/keps/current/nasa.all
I have some code that uses subprocess to look at the logs from a
I have some code that uses a form.submit() to open up another window when
I have some code that is structured as follows from my.modules import MyClass Class
I have some code that I'm using to get data from a network socket.
I have some code that I wrote to basically clear out the directory every
I have some code that prints out databse values into a repeater control on

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.