Hey there, I'm new to this and could really use your assistance,
I'm looking for a simple show/hide toggle feature when clicking on an image, where it switches between a 'side arrow' and a 'down arrow' (similar to a dropdown). The goal is to show/hide different text divs. However, I need to utilize classes instead of IDs due to integrating with .NET.
The current setup works with IDs, but I specifically require it to work with classes...
This is the function I have in place:-
<script type="text/javascript">
$(function(){
$('.nav-toggle').on('click', function(){
var t = $(this);
var imgSrc = t.attr('src');
var divId = t.attr('id');
$(divId).slideToggle('slow', function() {
if (imgSrc === '_includes/img/components/toggle_icon_show.png') {
t.attr({'src' :'_includes/img/components/toggle_icon.png'});
} else {
t.attr({'src' :'_includes/img/components/toggle_icon_show.png'});
}
});
});
});
</script>
HTML:-
<img src="_includes/img/components/toggle_icon.png" id="#1" class="nav-toggle">
<div id="1" style="display:none">
<p>Maecenas vulputate, augue vitae sagittis molestie, ipsum neque rhoncus turpis, sit amet iaculis sapien quam sed nunc. Donec neque erat, pulvinar non ultrices sit amet, dignissim at lectus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi in erat sapien. Nullam mi dolor, consectetur et turpis sit am.</p></div>
Appreciate your help!