jquery .empty() issue: doesn't work in plugin -


i have write simple plugin ajax load. page code. (result razor)

<a ajaxload="page" href="/brand">brand list</a>  <div id="plc1">   content </div>  <script type="text/javascript">         $(function () {             $("#plc1").ajaxpageload();         }); </script> 

in js code.

jquery.fn.ajaxpageload = function () {     $('a[ajaxload*="page"]').click(function () {         $(this).empty();         $(this).load(this.href);         return false;     }); } 

in page without implementation empty() work plug-in there no effect. wrong?

thanks.

seems you're hoping this refer both div , a @ same time.

if understand code, want empty element on plugin called when <a> element clicked.

currently, in click() handler, this <a> element. need retain reference <div> against plugin called outside handler.

jquery.fn.ajaxpageload = function() {       // reference <div> container (or whatever ends being)     var container = this;      $('a[ajaxload*="page"]').click(function() {         container.empty();           // empty container         container.load( this.href ); // load container href         return false;                //    of <a> clicked     }); };  $(function() {     $("#plc1").ajaxpageload(); }); 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -