I have been attempting to insert a button using .js into my HTML code. The purpose of this button is to appear every time I click on another button (identified with the id "imageChoose") which displays a preview of an image. This new button, labeled as removeButton (id: removeBttn), serves as a delete button for removing the displayed image and subsequently disappearing. Here is the HTML code snippet:
<div class="row fileinput-control">
<img id="preview" src="default5.png" width="500px" height="360px" style="padding-left:15px;" onload="addDeleteBttn()"/>
<br/>
<input type="file" id="image" style="display: none;" />
<a href="javascript:changeProfile()">
<div class="file-btns">
<span class="btn btn-default btn-file" id="imageChoose">
<i title="Select Image" class="fa fileinput-new fa-file-image-o"></i></span></div>
</a>
<a id="removeBttnFrame" href="javascript:removeImage()">
</a>
</div>
</div>
The following .js code adds the button along with some styling:
function addDeleteButton() {
var removeButton = document.createElement("BUTTON");
removeButton.title = "Remove";
removeButton.innerHTML = '<i class="fa fa-trash-o"></i>'
removeButton.class = "removeButtonClass";
document.getElementById("removeBttnFrame").appendChild(removeButton);
}
.removeButtonClass {
position: absolute;
top: 91%;
left: 22.7%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
background-color: white;
cursor: pointer;
border-radius: 5px;
color: black;
text-align: center;
border-color: lightgray;
height: 50px ! important;
width: 53px;
border-radius: 4px;
padding: 10x 17px;
border-width: thin
}
Although the button appears as expected, it lacks the intended styling. Strangely, the .css formatting seems to be completely disregarded. As someone new to HTML, I am struggling to find a solution. I have explored similar inquiries on How to dynamically create CSS class in JavaScript and apply? and also here: How to style dynamically created elements with CSS. Despite these resources, the issue remains unresolved. How can I resolve this problem?