Jump to content

innerhtml will swap once, but wont swap back


scarhand

Recommended Posts

code:

 

function loadnews()
{
  document.getElementById('newshead').innerHTML = document.getElementById('newshead1').innerHTML;
  document.getElementById('newstext').innerHTML = document.getElementById('newstext1').innerHTML;
  document.getElementById('newsheadsub').innerHTML = document.getElementById('newshead2').innerHTML;
}

function swapnews()
{
  if (document.getElementById('newshead').innerHTML = document.getElementById('newshead1').innerHTML)
  {
    document.getElementById('newshead').innerHTML = document.getElementById('newshead2').innerHTML;
    document.getElementById('newstext').innerHTML = document.getElementById('newstext2').innerHTML;
    document.getElementById('newsheadsub').innerHTML = document.getElementById('newshead1').innerHTML;
  }
  else
  {
    document.getElementById('newshead').innerHTML = document.getElementById('newshead1').innerHTML;
    document.getElementById('newstext').innerHTML = document.getElementById('newstext1').innerHTML;
    document.getElementById('newsheadsub').innerHTML = document.getElementById('newshead2').innerHTML;
  }
}

 

the body onload calls the "loadnews" function

 

im trying to get it so that they can swap back and forth whenever the person clicks on the link containing the "swapnews" function

 

so far it will only swap once, and wont swap back

you need to change the onclick event for your link; once the function is executes. something like this:

 

if (whatever.........) {

document.getElementById("mylink").onclick = function() {

// add function here

}

}

 

or you can used DOM to set a listener - either/or.........; would work

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.