Javascript / Jquery functions -


not sure if being totally wrong here want this:

  1. have external js page (on external server)
  2. include page - ok easy etc...
  3. have jquery function on external page - many functions
  4. call functions directly onto page.

all bit this:

external js page:

$(document).ready(function() {  function testit() { $('#test').load('page.php'); }  function testit_1() { $('#test_1').load('page_1.php'); }   function testit_1() { $('#test_2').load('page_2.php'); }  }); 

then on actual page call:

<script type="script/javascript">   testit();  </script>  <div id="test"></div> 

am wrong or should not work?

your functions local scope of anonymous function passed argument $(document).ready(). here's simple example showing behaviour you're seeing:

(function() {     function foo() {         alert("it shouldn't alert this...");     } })();  foo(); 

to fix it, move function declarations outside of ready function:

function testit() {     $('#test').load('page.php'); }  function testit_1() {     $('#test_1').load('page_1.php'); }   function testit_2() {     $('#test_2').load('page_2.php'); } 

and use ready function (shorthand $(function() { ... })) in main js file:

$(function() {     testit_1(); }); 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -