i’m trying to create my own tool in javascript, which will help me load some php functions/files into my div.
Here is my javascript:
$(document).ready(function () {
$('.btn').click(function() {
$('#someid').testit();
// $('#someid').load('somefile'); it works
return false;
})
});
function testit() {
$(this).load('somefile');
}
And my html:
<div id="someid"></div>
<form>
<input type="submit" value="test" class="btn" />
</form>
I can’t load the resource from external function – why is that?
If you want to call something like:
Then, you have to create a jQuery plugin that defines the method
testit. That code would look something like this:Then, and only then can you use
testit()as a jQuery method like this:And, it will operate on the desired selector.
Here’s some of the jQuery doc on writing plugin methods like this.