How to modify the id value of the child element under the id after the id object is cloned in js

Source: Internet
Author: User
How to modify the id value of the child element under the id after the id object is cloned in js



Untitled Document





Image 1 address:

Image 1 link:




Add an image
Delete an image
Generate code


Script
Var zhs = 0;

Var $ = function (cs ){
Return document. getElementById (cs)
};



Function tjs (){

Var sourceNode = $ ("tps _" + zhs );
Var clonedNode = sourceNode. cloneNode (true); // clone a node
Zhs = zhs + 1;
Var vbn = "tps _" + zhs
ClonedNode. setAttribute ("id", vbn );

SourceNode. parentNode. appendChild (clonedNode); // Insert a cloned node to the parent node.

}
Script


The above is the code that I wrote that only changed the parent id. the code that does not write can also modify the child element id value. I may not be clear about it. the code below is to do the following:




Untitled Document





Image 1 address:

Image 1 link:




Image 2 address:

Image 2 link:


Image 3 address:

Image 3 link:





Add an image
Delete an image
Generate code






Reply to discussion (solution)

Complete as function

function as() {  alert($('lbys').innerHTML);}
No error found after running

The id of p increments as expected.

On the 3q2 floor, I picked my code and forgot to pick the as () container. you may not understand what I mean.

I didn't understand what you mean.
Because you have not modified the input id code

I want to modify the input id.
Can I write

Can't write? Then you can make it clear.
Actually, you write it.

Function tjs () {var sourceNode =$ ("tps _" + zhs); var clonedNode = sourceNode. cloneNode (true); // clone node zhs = zhs + 1; var vbn = "tps _" + zhs clonedNode. setAttribute ("id", vbn); var o = clonedNode. childNodes; for (I = 0; I
    
  

3q: I only learned as2. now I want to learn js, so I don't know about js. thanks to my reply, I also came up with a stupid method.
It is wise to modify html content without the powerful code.
Function tjs (){

Var sourceNode = $ ("tps _" + zhs );
Var clonedNode = sourceNode. cloneNode (true); // clone a node
Zhs = zhs + 1;
Var vbn = "tps _" + zhs
ClonedNode. setAttribute ("id", vbn );

SourceNode. parentNode. appendChild (clonedNode); // Insert a cloned node to the parent node.

$ (Vbn). innerHTML = "image" + zhs + "address:"+" Image "+ zhs +" link:"
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.