?
Solved

innerHTML.replace image in IE

Posted on 2010-01-11
8
Medium Priority
?
809 Views
Last Modified: 2012-05-08
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

0
Comment
Question by:azlan28
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 4

Expert Comment

by:fsouzabrasil
ID: 26286039
try this:
On HTML:
<img src="images/minus.gif" align="absmiddle" id="imgx">

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

0
 

Author Comment

by:azlan28
ID: 26286210
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
 
LVL 11

Expert Comment

by:princeatapi
ID: 26286254
eg :
   <div id ="MyDiv" >
        <img src  = "..\Images\plus.gif" />
        </div>

Use Javascript as
document.getElementById("MyDiv").childNodes[0].src = "[Path Name]"
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

Author Comment

by:azlan28
ID: 26286881
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
 

Author Comment

by:azlan28
ID: 26288630
@princeatapi can you elaborate that example and apply it to my code above.
Thanks
0
 
LVL 4

Expert Comment

by:Mangagm
ID: 26289370
try this:

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

instead of

div.innerHTML.replace('View','Hide')
0
 
LVL 11

Accepted Solution

by:
princeatapi earned 2000 total points
ID: 26291037
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
 

Author Closing Comment

by:azlan28
ID: 31676021
Great! Thanks man that worked like a charm
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question