I have a rather simple question for once. I have delete buttons that open modal pop ups to confirm or deny deletion. I would like these modal pop ups to fade in on click and fade out on cancel. I've tried a few different things already, no luck so far. I just need a simple solution. Thanks in advance. Here's my code
<style>
div.delModal
{
position:absolute;
border:solid 1px black;
padding:8px;
background-color:white;
width:160px;
text-align:right
}
</style>
<script>
function showModal(id) {
document.getElementById(id).style.display = 'block';
//$(this).fadeIn('slow');
}
function hideModal(id) {
document.getElementById(id).style.display = 'none';
}
</script>
</head>
<body>
<input type ="button" value="delete" onclick="showModal('delAll1')">
<div class="delModal" style="display:none" id="delAll1">
<img src="images/warning.png" /> Are you sure you want to delete vessel and the corresponding tanks?<br />
<input type="button" value="Cancel" class="hide" onclick="hideModal('delAll1')"/>
<input type="button" value="Delete" onclick="delVesselAll(1)" id="delete"/>
</div>
</body>
Use
fadeIn()
on the right selector('#'+id
),this
in the current context would be the global object.DEMO
Why do not use id for each button like this
And the jquery like this
I wasn't satisfied with your first two comments so I made a new fiddle:
http://jsfiddle.net/dkmkX/
This will let you add multiple delete buttons each with their own modals.
There's a comment in the JS about how to find out which modal has been pressed, since this solution is ID independent.
Use
.fadeIn()
and.fadeOut()
on yourid
parameter ("delAll1"
) not onthis
.By using,
$("#" + id)
you can select an element by itsid
, that's"#" + id
.See it here.
Note: Change from
onLoad
tono wrap (head)
under framework on the left sidebar to fix the scope issue.