I have a javascript function to toggle a specific id sent to the function
<script type="text/javascript">
function toggle(id) {
var localId = document.getElementById(id)
if (localId.style.display == 'none') { localId.style.display = 'block' }
else { localId.style.display = 'none' }
}
</script>
I want to do the same in jQuery, I found some tutorials and I got one to work but I don't understand jQuery syntax at all and I am kinda confused.
$(document).ready(function(){
//Hide (Collapse) the toggle containers on load
$(".toggle_container").hide();
//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
$("h2.trigger").click(function(){
$(this).toggleClass("active").next().slideToggle("slow");
});
});
I got that to work with the next element but not with a specific id. I need it to be a specific id because I have almost 5 toggles per page and I find it easier to manage to ask the script to toggle by a specific id...
Just so that its clear, this is how I am using the javascript function:
<a href='javascript: toggle("rules_t")'>
<img src="lalala.png" id="rules" class="hoverOpacity" padding="5px"/>
</a>
<p id="text">A link to this season's official rules and related links.</p>
<div id="rules_t" style='display: none'> <?php include("gaga.php"); ?> </div>
Can someone help me convert that javascript into that smooth toggling jquery?