javascript - Getting value from this JQuery plugin -
i've been experimenting writing jquery plugins lately, , i'm sure simple question. but, seem not able value inside of plugin.
for example, have following code:
plugin.js
$(function($) { $.fn.myplugin = function() { // alert id main.js } });
main.js
$(document).ready(function() { $('#somediv').attr('id').myplugin(); });
you cannot define plugin on string
. use selector
call plugin.
have @ this.
use this:
(function ($) { $.fn.myplugin = function () { this.each(function () { // allow multiple element selectors alert(this.attr('id')); }); return this; // allow chaining } } (jquery)); $('.myclass').myplugin();
Comments
Post a Comment