Monday, August 19, 2013

Improve JQuery function for make it able to accept variables

Improve JQuery function for make it able to accept variables

This code is intended to be able to toggle between showing and hiding an
element depending on its ID. But in this form, only works with the ID's
that are already written in the code.
I would like to transform the code to make it possible to give it easily
the variables like in standard javascript functions. Something like
Function(id) {variable = id; actions;}
Like this, I would be able to employ this function always that I want to
hide or show an html element just calling the function and giving it a ID
as a attribute. Any idea on how to transform this code?
var x;
x=$(document);
x.ready(init);
function init(){
var x;
x=$("#check"); // Here is the ID of the control element
x.click(Qocult_most);
}
function Qocult_most(){ //Show and scrolls down till the page's end
var x;
x=$("#most"); //Here is the ID element to show
x.toggle(500);
$("html, body").animate({ scrollTop: $("#STH").offset().top },
1000);
}

No comments:

Post a Comment