I have to write a simple plugin for ajax load.
Page code. (result by razor)
<a ajaxLoad="page" href="/Brand">Brand List</a>
<div id="plc1">
some 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 this implementation empty() work properly but plug-in there is no effect.
what is wrong?
Thanks.
Seems that you’re hoping
thiswill refer to both thedivand theaat the same time.If I understand your code, you want to empty the element on which your plugin was called when the
<a>element is clicked.Currently, in the
click()handler,thisis the<a>element. You need to retain a reference to the<div>against which your plugin was called outside the handler.