Thursday, 15 September 2011

progressively convert from javascript to jquery -



progressively convert from javascript to jquery -

having existing - heavy loaded -set of web pages total of plain vanilla javascript code want progressively utilize jquery replacing of functions needed.

in other terms i'm hoping jquery won't forcefulness me rewrite whole thing scratch! if i'm right:

so there several existing javascript linked files (of mine) in typical document:

<script type="text/javascript" src="/play/dragdrop6.js"></script> <script type="text/javascript" src="/play/ahand6.js"></script> <script type="text/javascript"> var vstatus = "bid"; var curtop = 0; var curleft = 0; var curwidth = 0; var curheight = 0; function return2url() { history.go(-1); } function showsomethingb() { /... } </script></head><body>....

the question is: how add together jquery.min.js library document , set $(document).ready(function()...

say want rewrite function showsomethingb() in jquery style, set it?

just include link jquery library other javascript file.

generally first out of js files available start.

<script type="text/javascript" src="/jquery.{version}.js"></script> <script type="text/javascript" src="/play/dragdrop6.js"></script> <script type="text/javascript" src="/play/ahand6.js"></script>

then, go.

you can utilize $(document).ready(function() on (or every) page when want execute 1 time whole page loaded. jquery not limited that. can utilize anywhere.

however makes sense set @ to the lowest degree of js code in 1 place.

so code become:

<script type="text/javascript"> $(document).ready(function() { var vstatus = "bid"; var curtop = 0; var curleft = 0; var curwidth = 0; var curheight = 0; function return2url() { history.go(-1); } function showsomethingb() { } };

the rest on how want style , write js syntax.

the jquery docs great.

javascript jquery migration

No comments:

Post a Comment