innerHTML.replace image in IE

Hi,
Any alternative for this in IE. In Firefox is working just fine. It works also in IE if i choose not to show image for "+" and "-" state
Thanks
div.innerHTML = div.innerHTML.replace('<img src="images/minus.gif" align="absmiddle">','<img src="images/plus.gif">')

Open in new window

azlan28Asked:
Who is Participating?
 
princeatapiConnect With a Mentor Commented:
Just find the replacement like this
function showDiv(IdDiv,IdLink)
{
  if (document.getElementById)
      {      
        var layer =  document.getElementById(IdDiv) ;
        var div1 =  document.getElementById(IdLink) ;
    if(layer) {
        if (
              layer.style.display == 'block') {  
            layer.style.display = 'none';
div1.childNodes[0].src  = "../images/plus.gif";
div1.innerHTML = div.innerHTML.replace('Hide','View')
div1.style.color = '#5E4BE7';
} else {
layer.style.display = 'block';
div1.style.color = '#FF0000';
div1.childNodes[0].src  = "../images/minus.gif";
div1.innerHTML = div.innerHTML.replace('View','Hide') }
             }
      }
}

since you have only one item ( Say Image Tag inside the div ) it will be treated as childNode for the div ,  you can access it through div1.childNode[0]

Note: While declaring Variables please ensure that it should not be some pre defined tag names so i replaced all div with div1
0
 
fsouzabrasilCommented:
try this:
On HTML:
<img src="images/minus.gif" align="absmiddle" id="imgx">

On javascript:
document.getElementById("imgx").src = "images/plus.gif";

0
 
azlan28Author Commented:
Nope is not working or i'm doing something wrong. Here is all the code.
<div id="div1" onclick="showDiv('div1','id1');"><img src="images/plus.gif"> Show Div</div>

function showDiv(IdDiv,IdLink)
{
  if (document.getElementById)
      {      
var layer =  document.getElementById(IdDiv) ;
var div =  document.getElementById(IdLink) ;
  if(layer) {
  if (layer.style.display == 'block') {  
layer.style.display = 'none';
div.innerHTML = div.innerHTML.replace('<img src="images/minus.gif" align="absmiddle">','<img src="images/plus.gif">')
div.innerHTML = div.innerHTML.replace('Hide','View')
div.style.color = '#5E4BE7';
} else {
layer.style.display = 'block';
div.style.color = '#FF0000';
div.innerHTML = div.innerHTML.replace('<img src="images/plus.gif">','<img src="images/minus.gif" align="absmiddle">')
div.innerHTML = div.innerHTML.replace('View','Hide') }
             }
      }
}

Open in new window

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
princeatapiCommented:
eg :
   <div id ="MyDiv" >
        <img src  = "..\Images\plus.gif" />
        </div>

Use Javascript as
document.getElementById("MyDiv").childNodes[0].src = "[Path Name]"
0
 
azlan28Author Commented:
C'mon i bet is a simple solution. I told you in Firefox is working so i think i just have to replace this function innerHTML.replace with something compatible for IE
0
 
azlan28Author Commented:
@princeatapi can you elaborate that example and apply it to my code above.
Thanks
0
 
MangagmCommented:
try this:

div.innerHTML.toString().replace('View','Hide')

instead of

div.innerHTML.replace('View','Hide')
0
 
azlan28Author Commented:
Great! Thanks man that worked like a charm
0
All Courses

From novice to tech pro — start learning today.