Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Change visibility of a link with Javascript?

I am trying to create a bit of javascript that will change a hidden URL to visible once people click on a link. The element siteurl is set to display:none in the CSS file.

Here is my code:

function changeurl() {

if (document.getElementById(siteurl).style.display = 'none')

{

(document.getElementById(siteurl).style.display = 'visible')

}

}

And here is the rest of my code to put it into perspective:

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Wordpress Websites</title>

<link href="home2012 css.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">

function changeImage(newimage) {

var changeimg = document.getElementById("imgchange");

changeimg.src = newimage;

}

function changedescription(newtext) {

var description = document.getElementById("description");

description.innerHTML = newtext;

}

function changewebaddress(newtext) {

var webdescription = document.getElementById("webdescription");

webdescription.innerHTML = newtext;

}

function changeurl(newurl) {

var siteurl = document.getElementById("siteurl").href = newurl;

siteurl.innerHTML = webdescription;

siteurl.href = newurl;

}

function changeurl() {

if (document.getElementById(siteurl).style.display = 'none')

{

(document.getElementById(siteurl).style.display = 'visible')

}

}

</script>

</head>

<body>

<div class="maincontainer">

<div class="navshow" id="navshow">

<ul class="navshow">

<li class="liheadingshow">

<h2>Wordpress Websites</h2>

</li>

<li><a href="#" onclick="changeImage('imgs/sampleMIC.gif'),

changedescription('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras dui justo, cursus quis varius mattis, convallis nec justo. Suspendisse potenti. Suspendisse quis mauris lorem. Maecenas at nunc tortor, nec laoreet velit.'),

changeurl('http://meditateincopenhagen.org/')

; return false">Meditate in Copenhagen</a></li>

<li><a href="#" onclick="changeImage('imgs/sampleMIB.gif'), changedescription('In laoreet sem vel mi suscipit placerat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.'),

changeurl('http://meditasjonibergen.no/')

; return false">Meditate in Bergen</a></li>

<li><a href="#" onclick="changeImage('imgs/sampleNDC2012.gif'), changedescription('Proin facilisis velit vitae augue semper vitae sodales odio malesuada. In a nisl sit amet dui placerat rutrum vel vel tellus. Phasellus leo velit, pharetra id scelerisque eget, volutpat eu ipsum. Pellentesque eget ante justo, vel dignissim odio.'), changeurl('http://kadampafestivals.org/scandinavia/')

; return false">2012 - Nordic Dharma Celebrations</a></li>

<li><a href="webdesign.html">Back</a></li>

</ul>

</div> <!--End of navbar -->

<div class="imgflipshow">

<p><img src="imgs/wordpresspage.png" width="350" height="200" id="imgchange"/></p>

<p class="description" id="description">Click on one of the site from the menu to learn more.</p>

<a id="siteurl" href="">Click here to visit the site!</a>

</div>

</div>

<div class="legal">Site Created by David Hirst 2011 - 2012. The website is licened under Creative Commons Licence BY, NC, SA. For more infomation click here. The images used on this website are copyright of there respective creators. See source code for more infomation. </div>

</body>

</html>

Thanks in advance for your help :).

2 Answers

Relevance
  • 9 years ago
    Favorite Answer

    use style.display = 'block';

  • 9 years ago

    You have two changeurl functions. The second is overwriting the first.

    In the second you have:

    if (document.getElementById(siteurl).style...

    Quotes are missing around siteurl. I think you mean to pass the function siteurl as an argument. It seems you forgot to add it as an argument in the function.

    You have:

    function changeurl()

    Instead of:

    function changeurl(siteurl)

    You should try and keep your JavaScript separate from your HTML. Cramming everything into the onclick attribute will make debugging your code troublesome.

    - Dominic

Still have questions? Get your answers by asking now.