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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.