I guess you want to add an img element image after your innerHTML text.
If that is the case,
var Bearing = document.getElementById("rptAracDetay_Label28_0");
if (Bearing.innerHTML.replace(': ', '') == '0') {
Bearing.innerHTML = ': North';
var img = document.createElement('img');
img.src = 'https://xyz/x.png';
Bearing.appendChild(img);
}
else if (Bearing.innerHTML.replace(': ', '') == '180') {
Bearing.innerHTML = ': South';
var img = document.createElement('img');
img.src = 'https://xyz/y.png';
Bearing.appendChild(img);
}
Upvote if you find it useful.
I think your if/else portion is being executed before actually Bearing variable initiated. So use a if condition to check if Bearing variable is actually initiated or not like:
if(Bearing){
//do your stuff;
}
Not sure what you are trying to achieve, but I would say
const Bearing = document.getElementById("rptAracDetay_Label28_0");
Bearing.innerHTML.replace(': ', '') === '0' ?
Bearing.innerHTML = ': North' : Bearing.innerHTML = ': South';
Also, is '0'
and '180'
a string or a number? Does Bearing
needs to be capital for some reason?
The below Js Code is working. I want to add a picture here. If the value is 0 then x.png is 180 then y png.
how can I do that. I will be glad if you help.
Thank you
var Bearing = document.getElementById("rptAracDetay_Label28_0");
if (Bearing.innerHTML.replace(': ', '') == '0') {
document.getElementById("rptAracDetay_Label28_0").innerHTML = ': North';
}
else if (Bearing.innerHTML.replace(': ', '') == '180') {
document.getElementById("rptAracDetay_Label28_0").innerHTML = ': South';
}
There is no need in refetching the element inside the conditions.
no background picture. I want to add an image to the end of the line immediately.
End of line means under the same element with id “rptAracDetay_Label28_0” right? and you want to add img HTML element. correct me if I am wrong.
@ErhanŞimşek please check the edited answer.
command works no problem. I just want it to add a picture according to the values I gave to the end of the line. no background
command works no problem. I just want it to add a picture according to the values I gave to the end of the line. no background