Hi,
I'm trying to create a toggler object. Its my first stab at object oriented javascript. I've basically got two functions that I've put together to manipulate an anchor. Its not working but i don't think i'm that far off. It just shows and hides a div whilst changing the link text at the same time.
html:
If anyone could point me in the right direction, or simply tell me i'm a long way of understanding object oriented javascript, that would be great.
I'm trying to create a toggler object. Its my first stab at object oriented javascript. I've basically got two functions that I've put together to manipulate an anchor. Its not working but i don't think i'm that far off. It just shows and hides a div whilst changing the link text at the same time.
Code:
function toggler(element, layerid, newtext) { var layerid = document.getElementById('info'); function showhide(layerid){ if(layerid.style.display == "none"){ layerid.style.display = "block"; } else{ layerid.style.display = "none"; } } var originaltext = element.innerHTML; function replacetext() { if(element.innerHTML == originaltext){ element.innerHTML = newtext; } else{ element.innerHTML = originaltext; } } }
Code:
<a id="toggle" href="javascript:toggler(this 'info', 'close')">Find out more</a></p>