I’ll barge in on this again 😉 .
$(function() {
<!--$("#rssInfo").hide();-->
var rssInfo = $("#rssInfo");
var rssInfoClose = $("a#rssInfoClose");
$("a#subscribeRollover").click(function () {
rssInfo.animate({ opacity: "show" }, "slow");
return false;
});
rssInfoClose.click(function () {
rssInfo.animate({ opacity: "hide" }, "slow");
return false;
});
});
Is that correct?
Almost. You’re closing the click function too soon, so that first closing bracket you added should be followed by a comma, and not ); .
The click function essentially takes an unlimited number of arguments. All of them functions. If there is more than one argument it cycles through them on each click. So let’s say a, b, and c are functions:
a = function() { /* do something */ }
b = function() { /* do something */ }
c = function() { /* do something */ }
$('#whatever').click(a, b, c);
When I click the ‘whatever’ div, it runs function a. I click it again, it runs b. Then c, and back to a again.
In javascript functions don’t need names, you could just put the functions themselves into the parameters - those are called anonymous functions.
$('#whatever').click(function() {/*stuff*/},
function() {/*stuff*/},
function() {/*stuff */});
So for your original problem. You would hide the div when the page loads.
And then attach the click handlers. However in this case you need two, because the click function only listens to one element.
So, using regular functions because it’s easier to read, you would do something like this:
var showit = function() {
$('rssdiv').show();
return false;
}
var hideit = function() {
$('rssdiv').hide();
return false;
}
$('#rssdiv').hide();
$('#subscribe').click(showit);
$('#closerss').click(hideit);
Then you can replace those show() and hide() actions with more fancy animations (which is what I thought the original problem was 😉 ).
Hope that helps.
[Edit: On returning false, that just tells the browser not to act on the click. So you will stay on the same page.]