Javascript - hide div box - having trouble!

Associate
Joined
3 Nov 2005
Posts
611
These are a few extracts from a page I am working on. Any obvious problems?

Code:
<script type="text/javascript">
function close(id)
{
document.getElementById('id').style.display = 'none';
}
</script>

<div id="maker_prompt">Not sure what to have? Try out our meal maker!
<div id="maker_close">
<a href="#" onclick="close('maker_prompt')">x</a>
</div>

IE9 and Firefox refuse to close the maker_prompt div...
 
By quoting 'id' you're sending in a literal with the string value 'id', and not your id argument.

Remove the quotes and you're good.

Thanks Goof! I'll try it later after work but I'm sure that will do the business. Fairly new to this Javascript lark as is clearly obvious ;)
 
Hmmm, think I might be being stupid again as it isn't working...

Code:
<script type="text/javascript">
function close(id)
{
document.getElementById(id).style.display = 'none';
}
</script>


<div id="maker_prompt">Not sure what to have? Try out our meal maker!
<div id="maker_close">
<a href="#" onclick="close(maker_prompt)">x</a>
</div>

Good option there lokkers. Might have to look into that as well. Note - I've tried this with quotes in the close argument around maker_prompt and without.
 
Lokkers - it required the 'javascript:' bit as you suggested to work correctly but work it did. Any reason why I needed that part? I thought it may just reference the function in the head without that? Examples I look at don't appear to need it?
 
Back
Top Bottom