add image inside a div on specific position javascript 1

add image inside a div on specific position javascript

function updateDiv(id, width, height, left, top, opacity) 
{ 
    var mydiv = document.getElementById(id);
    mydiv.setAttribute('id', id);  

    mydiv.style.width =  width + "px";     
    mydiv.style.height = height + "px";     

    mydiv.style.position = "absolute"; 
    mydiv.style.left = left + "px";         
    mydiv.style.top = top + "px";  

    mydiv.style.opacity = opacity;
}

Here is what the above code is Doing:
1. It creates a function called updateDiv that takes in 6 parameters: id, width, height, left, top, and opacity.
2. It then gets the div with the id that was passed in.
3. It sets the width and height of the div to the width and height that was passed in.
4. It sets the position of the div to absolute.
5. It sets the left and top position of the div to the left and top position that was passed in.
6. It sets the opacity of the div to the opacity that was passed in.

Now that we have the updateDiv function, we can use it to update the position and opacity of the divs.

Similar Posts