Pass Jquery alias into javascript function -
im creating theme wordpress , need use jquery. ive found bits of code online , ive made few bits myself. however, when using jquery provided wordpress in noconflict mode , instead of using $ set "jquery". fine dont want have modify code , code find online use "jquery" instead of $.
so tells me placeing function ($) @ end able use $ jquery alias, in functions scope. fine, hoping work , pass through functions call inside scope. problem is. how can make jquery code uses $ inside "resizeandcenter" function work.
jquery('.artworklist > li > > img').load(function ($){ resizeitems('artworklist'); }); this function want able use $ inside dont want have modify code / , code find online.
function resizeitems(elementname){ //do jquery stuff using $ } perhaps there alternative way doing or doing wrong?
edit:
my function "resizeitems" on own in js file thats included in page header.
the other code, jquery code in first code block @ bottom of page in script block.
so im bit unsure answer saying wrap function?
you need pass jquery top-level closure containing code. inside $(document).ready() call. basic example looks this:
jquery(function($) { function resizeitems(elementname){ //do jquery stuff using $ } $('.artworklist > li > > img').load(function (){ resizeitems('artworklist'); }); }); jquery aliased $ inside of closure.
Comments
Post a Comment