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(); 

demo

tutorial


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -