How to edit the div node name using js _ javascript tips-js tutorial

Source: Internet
Author: User
This article mainly introduces how to edit the div node name in js, and how to edit the div node name and select the style, it also selects and controls the style of IE and FF browsers, which has some reference value, for more information about how to edit the p node name in js, see the example in this article. Share it with you for your reference. The specific implementation method is as follows:

The node html code is as follows:

The Code is as follows:



123



Edit the noteTxt text in js. The function is as follows:

The Code is as follows:

Function changeName (noteTxtId ){
Var noteTxt = document. getElementById (noteTxtId );
NoteTxt. style. display = "none"; //. style. display = "block"

Var p = noteTxt. parentNode;

If (! Document. getElementById ("noteInput ")){
Var text = document. createElement ("input ");
Text. type = "text ";
Text. id = "noteInput ";

Text. style. width = getStyle (noteTxt, 'width ');
Text. style. height = getStyle (noteTxt, 'height ');
Text. style. marginTop = getStyle (noteTxt, 'margintop ');
Text. style. textAlign = getStyle (noteTxt, 'textign ');

Text. value = noteTxt. innerHTML;
P. appendChild (text );
Text. select ();
Text. onblur = function (){
NoteTxt. style. display = "block ";
NoteTxt. innerHTML = text. value;
// Text. style. display = "none ";
P. removeChild (text );
}
}
}

// Obtain the style in the css file
Function getStyle (obj, attr)
{
If (obj. currentStyle)
{
Return obj. currentStyle [attr]; // IE
} Else {
Return getComputedStyle (obj, false) [attr]; // FF
}
}

Css:

The Code is as follows:

. Img_1 {
Width: 80px;
Height: 70px;
Position: absolute;
}

. NoteText {
Width: 80px;
Height: 15px;
Text-align: center;
Margin-top: 70px;
Word-break: break-all;
}

I hope this article will help you design javascript programs.

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.