With my website I'm trying to do some JQuery which I thought would be simple (as a beginner):
- Click a div/button in a news header.
- As a result, have the image in it rotate/replaced (arrow).
- As a result, create a scrollbar in the div below the header.
- Click the div/button again and it toggles back to its original position.
I've managed to make things work, but only with two separate divs/arrows, this in the following manner:
$(document).ready(function(){
$('.scroll').css('cursor', 'pointer').on('click', function() {
$('.news-section-links-internal-1').css({
overflow: 'scroll',
marginRight: '0px',
width: '230px',
paddingRight: '15px'
});
});
$('.noscroll').css('cursor', 'pointer').on('click', function() {
$('.news-section-links-internal-1').css({
overflow: 'hidden',
marginRight: '15px',
width: '225px',
paddingRight: '0px'
});
});
});
It looks a little crude though, so I've been trying to combine this code so it works with one toggle div/button based on tips found on Stackoverflow. Below is an example of that:
$(document).ready(function(){
$(".scroll").css('cursor', 'pointer').toggle( function() {
$('.news-section-links-internal-1').css({
overflow: 'scroll',
marginRight: '0px',
width: '230px',
paddingRight: '15px'
});
}, function () {
$('.news-section-links-internal-1').css({
overflow: 'hidden',
marginRight: '15px',
width: '225px',
paddingRight: '0px'
});
});
});
Unfortunately, the combined code never works. In the above example the toggle div/button simply fades out when I load the page and that's it.
Can anyone help me with this problem? I don't need a whole lot of JQuery on my page, but this is quite crucial. Been trying for two days.
If it helps, here's all the relevant CSS:
.news-section-links {
background-color: #fffffc;
width: 245px !important;
padding-right: 0px;
padding-left: 5px;
padding-top: 1px;
border-left: 1px solid #000;
border-right: 1px solid #000;
border-bottom: 1px solid #000;
}
.news-section-links-internal-1 {
width: 225px;
height: 200px;
background-color: #fffffc;
margin-right: 15px;
overflow: hidden;
}