html - Improve JQuery function for make it able to accept variables -


this code intended able toggle between showing , hiding element depending on id.

i'm trying transform code make possible give variables in standard javascript functions.

like this, able employ function want hide or show html element calling function , giving id attribute.

i'm trying version of code doesn't work. i'm giving id's of elements want change there mistake.

var x; x=$(document); x.ready(init);  function init(){             var x;             x=$("#titulo1");  // here id of control element             x.click(qocult_most("#subtitulo1"));             }  function qocult_most(id){  //show , scrolls down till page's end             var x;             x=$(id); //here id element show             x.toggle(50);             $("html, body").animate({ scrolltop: $("#sth").offset().top }, 1000);                     } 

and html body calls jquery is:

 <body>   <div id="titulo1" class="contenedor"> i'm title 1    <div id="subtitulo1">  text show sub-menu when title 1 clicked</div>  <div id="titulo2" class="contenido"> i'm title 2   </div>  </div>   </body> 

something this?

function init(){   var x = $("#check");  // here id of control element   x.click(     function() {       qocult('#most');     }   ); }  function qocult(id) {  //show , scrolls down till page's end   var x = $(id);    x.toggle(500);   $("html, body").animate(     { scrolltop: $("#sth").offset().top }, 1000   ); }  $(document).ready(init); 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -