I'm trying to make my link toggle from left to right. I'm using the code below;
HTML:
$forum_threads = '
<div id="latest_threads_link">
<a href="javascript:void(0)" id="latest_threads_click"><img src="images/kalachi/latest_threads.png" alt="Latest Threads" title="Click Here to see latest threads of this section."></a>
<table border="0" cellspacing="'.$theme['borderwidth'].'" cellpadding="'.$theme['tablespace'].'" class="tborder" style="display: none;" id="latest_threads_show">
'.$forum_threads_bit.'
</table>
</div>
';
jQuery:
jQuery(document).ready(function($){
$('a[id^="latest_threads_click"]').on('click', function (e){
e.preventDefault();
$('#latest_threads_show').slideToggle();
$('#latest_threads_click').addClass('latest_threads_link_active');
});
});
CSS:
#latest_threads_link{
left:0;
position:fixed;
bottom:150px;
}
.latest_threads_link_active{
left:200px;
position:fixed;
bottom:150px;
}
I want to make it so when #latest_threads_link is clicked then #latest_threads_show toggleout from left to right and on second click on #latest_threads_link then the table #latest_threads_show hides.
It actually does with my code but the issue is the #latest_threads_link remains on 200px away from left even on second click. I want #latest_threads_link to go left: 0 on second click.
Please help!!
.toggleClass('classname')is the solution.$('#latest_threads_click').slideToggle()is just$(this).slideToggle()and$('a[id^="latest_threads_click"]')is faster as just$('#latest_threads_click')(assuming there aren't other id's starting withlatest_threads_click)