macleodjb
12-11-2009, 12:26 AM
Hi guys,
I have this little snippet of code that swaps a toggle image for news for a plus or minus sign showing if the div is open or closed. This code has worked before but i made a couple modifications today and it stopped working unexpectedly and i'm not sure why its failing.
I am presetting the div tag with a plus sign with css and then modifying it with javascript. The problem i am having is that when the div tag has been opened it does not swap the image to min.gif anylonger. It remains max.gif.
Here's the javascript code
var News_Images = new Array();
News_Images[0]="images/max.gif"
News_Images[1]="images/min.gif"
function DisplayNews(body,box,link,id){
$(body + " > div > .news_box").each(function(){
if($(this).css("display")=="block"){
$(this).slideToggle("slow");
}
});
$(body + " > div > a[class='open_button_closed']").each(function(){ // search and change the + / - images
$(this).css("background-image",'url('+script_path+News_Images[0]+')');//
});
$(body + " > div > a[class='open_button']").each(function(){
$(this).css("background-image",'url('+script_path+News_Images[0]+')');//
});
if($(body + " > div > #"+box+id).css("display")=="none"){
$(body + " > div > #"+box+id).slideDown("slow");
$(body + " > div > #"+link+id).css("background-image",'url('+script_path+News_Images[1]+')');//
alert("box =" + box + " id = " + id + " link =" + link);
}
}
And here is the html sample
<div class="recent_news_box">
<a onclick="DisplayNews('#display_recent','news_link','open_button',3); return false;" id="open_button3" class="open_button"></a>
<a class="link_block" href="">Some Title Text</a>
<div style="display: none;" class="news_box" id="news_link3">
<img class="front_image" alt="" src="" align="right">
<span class="date">Jul 21, 2009</span>
<div>Some Stuff to display here will be short text</div>
</div>
</div>
Thanks in advance.
I have this little snippet of code that swaps a toggle image for news for a plus or minus sign showing if the div is open or closed. This code has worked before but i made a couple modifications today and it stopped working unexpectedly and i'm not sure why its failing.
I am presetting the div tag with a plus sign with css and then modifying it with javascript. The problem i am having is that when the div tag has been opened it does not swap the image to min.gif anylonger. It remains max.gif.
Here's the javascript code
var News_Images = new Array();
News_Images[0]="images/max.gif"
News_Images[1]="images/min.gif"
function DisplayNews(body,box,link,id){
$(body + " > div > .news_box").each(function(){
if($(this).css("display")=="block"){
$(this).slideToggle("slow");
}
});
$(body + " > div > a[class='open_button_closed']").each(function(){ // search and change the + / - images
$(this).css("background-image",'url('+script_path+News_Images[0]+')');//
});
$(body + " > div > a[class='open_button']").each(function(){
$(this).css("background-image",'url('+script_path+News_Images[0]+')');//
});
if($(body + " > div > #"+box+id).css("display")=="none"){
$(body + " > div > #"+box+id).slideDown("slow");
$(body + " > div > #"+link+id).css("background-image",'url('+script_path+News_Images[1]+')');//
alert("box =" + box + " id = " + id + " link =" + link);
}
}
And here is the html sample
<div class="recent_news_box">
<a onclick="DisplayNews('#display_recent','news_link','open_button',3); return false;" id="open_button3" class="open_button"></a>
<a class="link_block" href="">Some Title Text</a>
<div style="display: none;" class="news_box" id="news_link3">
<img class="front_image" alt="" src="" align="right">
<span class="date">Jul 21, 2009</span>
<div>Some Stuff to display here will be short text</div>
</div>
</div>
Thanks in advance.