SoFunction
Updated on 2025-03-08

js method to edit div node name

This article describes the method of editing div node names by js. Share it for your reference. The specific implementation method is as follows:

The node html code is as follows:

Copy the codeThe code is as follows:
<div class="img_1" >
     <input type="image" class="img_1" src="img/"></input>
     <div class="noteText" type="text" ondblclick ="changeName();">123</div>
</div>

js edit noteTxt text, the function is as follows:
Copy the codeThe code is as follows:
function changeName(noteTxtId){
        var noteTxt = (noteTxtId);
        = "none";//.= "block"

        var div = ;

        if(!("noteInput")){
            var text=("input");
            ="text";
            ="noteInput";

            =getStyle(noteTxt,'width');
            =getStyle(noteTxt,'height');
            =getStyle(noteTxt,'marginTop');
            =getStyle(noteTxt,'textAlign');

            =;
            (text);
            ();
            =function(){
                = "block";
                =;
                //= "none";
                (text);
        }
        }
     }

//Get the style in the css file
     function getStyle(obj, attr)
     {
        if()  
        {
        return [attr];  //IE
        }else{              
        return getComputedStyle(obj,false)[attr];  //FF
     }
}

CSS is as follows:

Copy the codeThe 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 be helpful to everyone's JavaScript programming.