nicoschuck nicoschuck - 2 months ago 11
jQuery Question

JS Toggle doesnt works

i need some help with my website.
I want to integrate the jquery toggle function. But it doesnt works.
I have not a lot experience with jquery.

Here is my code:

<a href="javascript:toggle('exp');">Klick</a>

<div id="exp" style="display:none;"> hallo </div>

<script src="jquery-ui-1.10.3/js/jquery-1.9.1.js"></script>
<script src="jquery-ui-1.10.3/js/jquery-ui-1.10.3.custom.js"></script>
<script>
function toggle(str)
{
$(str).slideToggle('slow');
}
</script>


Has anyone an idea why it doesnt works?

Answer

Missing # before id selector in your code.

function toggle(str){
    $('#' + str).slideToggle('slow');
    //-^----
}