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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:50:29+00:00 2026-06-08T02:50:29+00:00

can anyone please advise what may be wrong with my script below? It should

  • 0

can anyone please advise what may be wrong with my script below?

It should look for the last DIV with #objec in the class name, and then look for the last input element within the DIV, then add a new DIV with incremented ID/Names below the one there already. I think this is the line which is going wrong:

var name = $("#objec:last>input").attr("name");

The code is here: http://jsfiddle.net/mtait/9MbQH/6/

…and below.

Thank you,

Mark

<label id="add_tag"> 
     Click me to add a new row
</label> 


<div class="objec">
    <div class="row">
        <div class="span4">
            <input class="span4" data-val="true" data-val-required="Objective&#32;is&#32;required" id="Objectives_7__objective" name="Objectives[7].objective" type="text" value="Timecard Completion" />
        </div>
     </div>
</div>


$(document).ready(function() {
var re = /\[(.*?)\]/;
$("#add_tag").click(function() {
    var name = $("#objec:last>input").attr("name");
    var m = re.exec(name);
    var itemNumber = parseInt(m[1]) + 1;
    var $newdiv1 = $('<div class="objec"><div class="row"><div class="span4"><input class="span4" data-val="true" data-val-required="Objective&#32;is&#32;required" id="Objectives_' + itemNumber + '__objective" name="Objectives[' + itemNumber + '].objective" type="text" value="..." /></div></div>');
    $(".objec:last").after($newdiv1);
    return false;
});
});
  • 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-08T02:50:30+00:00Added an answer on June 8, 2026 at 2:50 am

    Probably you want this:

    var name = $(".objec:last input").attr("name");
    

    Live demo

    Read about the differences between Descendant combinator and Child combinators.

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

Sidebar

Related Questions

Can anyone please advise where i'm going wrong with the following? I want the
Can anyone please advise what is the best to achieve the below: Requirement: Drop
Can anyone please advise me if there will be any problems changing the wordpress
Would anyone please advise how in jade for nodejs I can truncate a string
Hi Can anyone please advise me on how to host an asmx webservice build
Can anyone please advise the syntax for passing a table FROM a SAS library
Please can anyone advise me on how i can replace a particular character from
In sql server 2005/2008, can anyone please advise me on how can i generate
Can anyone advise please? I'd like to have the default page for visitors to
http://www.streetstyles4all.co.uk/test4.html Can anyone please advise. I have finished my menu now and it works

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.