I have a 'setVisibility' function code with a single button that works well, courtesy of JRulle in this post:
Animate Javascript show / hide button.
When button is clicked, it will fade in some text, then when clicked again it fades it out. All good.
However, when I duplicate the code including the script to work in another location down the page, I can't get the first one to work independantly of the added one and visa versa.
Any ideas gratefully received.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>setVisibility</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<style type="text/css">body {text-align: center; font-family: Arial; text-align: center;} input {font-size: 1.1em;}</style>
</head>
<body><br /><br />
<!--/ FIRST INSTANCE \-->
<script>
function setVisibility(id1) {
if($('#bt1').val() == 'Hide'){
$('#bt1').val('Which means ..');
$('#' + id1).fadeOut();
}
else{
$('#bt1').val('Hide');
$('#' + id1).fadeIn();
}
}
</script>
Lorem ipsum dolor sit amet, etc.
<div style="display: none;" id="sub1"> <br /> Which means...
<div style="height: 1em;"></div>
Let's see what loves or pursues or desires the pain, etc.
</div> <div style="height: 1em;"></div>
<input type=button name=type id='bt1' value='Which means ..' onclick="setVisibility('sub1');">
<div style="height: 1em;"></div><hr />
<!--/ SECOND INSTANCE \-->
Another instance needed here.
</body>
</html>