jQuery Call a Function in Addition to some other code
I'm trying to call a function into another function to get rid of some redundant code. The 'test' function is a standard piece of repetitive code, so I don't want to keep writing it out along with the custom animation.
(function test() {
do this
});
/* =========================Standard code========================= */
$(function () {
$('#div').click(EXECUTE THE 'TEST' FUNCTION HERE AND THEN...function() {
$('#timeline').stop().animate({
left : "+=500px"
});
});
});
Here is the solution thanks to the kind guys below:
开发者_JAVA技巧function test() {
do this
}
/* =========================Standard code========================= */
$(function () {
$('#div').click(function() {
test();
$('#timeline').stop().animate({
left : "+=500px"
});
});
Is there anything wrong with:
$(function () {
$('#div').click(function() {
test();
$('#timeline').stop().animate({
left : "+=500px"
});
});
??
You would put your call to test()
above the $('#timeline')....
line.
why you are using round braces around the test() function?
Can you try with an ALERT box in test() function?
精彩评论