I want to add svg image via DOM manipulation, instead of adding them in HTML DIV?
I have tried everything by googling but couldnot find any better solution for it. Instead of 'X' i want to insert the svg image (assets/close.svg) inside the span element. which is inside the 'studentDetails' Div. Will be grateful for your help.
HTML:
<div id="studentDetails" class="hidden"></div>
javascript:
var studentDetails = document.getElementById('studentDetails');
var favouriteStudent =
contacts[parseInt(e.currentTarget.id)].favourite ? 'favourite' : '';
studentDetails.innerHTML =
"<span id='close-details'>x</span>" +
"<span id='favourite' class='" +
favouriteStudent +
"'>*</span>" +
'<div>' +
contacts[parseInt(e.currentTarget.id)].name +
'</div>' +
'<div>' +
contacts[parseInt(e.currentTarget.id)].email +
'</div>';
studentDetails.setAttribute('class', 'hidden');
CSS:
#close-details {
display: block;
float: right;
font-size: 20px;
margin-top: -8px;
background-image: url('assets/close.svg');
background-repeat: no-repeat;
background-position: right;
}