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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:16:47+00:00 2026-06-15T01:16:47+00:00

interesting one. i’m working on a big, modular form that the user can add

  • 0

interesting one. i’m working on a big, modular form that the user can add or remove services in and need to reach into the DOM, copy an HTML element, and add a value to the end of both it and it’s children’s ID’s.

So for example:

<li id="serviceModule" class="serviceModule">
    <ol>
        <li id="subModuleTypeA">subModule</li>
        <li id="subModuleTypeB">
            <ol>
                <li id="subModuleTypeASubModuleX">subSubModule</li>
                <li id="subModuleTypeASubModuleY">subSubModule</li>
                <li id="subModuleTypeASubModuleZ">subSubModule</li>
            </ol>
        </li>
        <li id="subModuleTypeC">subModule</li>
    </ol>
</li>

Would become:

<li id="serviceModule1" class="serviceModule">
    <ol>
        <li id="subModuleTypeA1">subModule</li>
        <li id="subModuleTypeB1">
            <ol>
                <li id="subModuleTypeASubModuleX1">subSubModule</li>
                <li id="subModuleTypeASubModuleY1">subSubModule</li>
                <li id="subModuleTypeASubModuleZ1">subSubModule</li>
            </ol>
        </li>
        <li id="subModuleTypeC1">subModule</li>
    </ol>
</li>

Method that adds value:

$.fn.valulator = function(magic){

    var thiis = $(this),
        el,
        id;

    thiis.add(thiis.children()).each(function(){

        el = $(this);
        id = el.attr('id');

        el.attr('id', id + magic);
    });

    return this;
};

Binding that triggers valulator:

$add.click(function(event){

    event.preventDefault();

    $index = $index + 1;
    $('.serviceModule')
        .clone()
        .valulator($index)
        .appendTo('#services');
});

Thanks for your help! Here’s a jsFiddle:
http://jsfiddle.net/phqvr/3/


UPDATE

Finding that the first issue i’m running into within valulator() is that children() only brings up direct descendants.. instead i need to search ALL elements.

  • 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-15T01:16:48+00:00Added an answer on June 15, 2026 at 1:16 am

    Got it; there were two issues.

    1) as mentioned in the update, children() only traversed one level down- reworked it to:

    thiis.find('*').andSelf().each()
    

    2) in my Fiddle, there was an added conditional if(el[id]) that would always fail. replaced with below code to prevent additions to elements that didn’t have ID’s to begin with:

    if (id){}
    

    Full working code here: http://jsfiddle.net/phqvr/4/

        $.fn.valulator = function(magic){
    
            var thiis = $(this),
                el,
                id;
    
            thiis.find('*').andSelf().each(function(){
    
                el = $(this);
                id = el.attr('id');            
    
                if (id){
    
                    el.attr('id', id + magic);
                }
            });
    
            return this;
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interesting one. I have a WP site that I need to
One interesting aspect of extension methods in .NET is the fact that you can
Today I found one interesting thing. I didn't know that one can't declare a
Interesting one here. I have an ASP.NET 1.1 project that contains a web service
I had old phone with one interesting functionality, that was ability to turn on
Here's an interesting one... hope I can explain it well... I have a collection
Hey all, another interesting one, I'm building a menu that will slide across the
I need to create a program that makes XML editing possible in user-friendly way.
There is one interesting widget in jquery-ui: dialog window . But I can't find
Here is an interesting one... I have an application I am writing for devices

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.