SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question New to jQuery - Trying to build basic Plugin

    Hello - Just trying to build a basic plugin (below) to see how it works and when I try to call "listElements" from
    my main page I get "Object doesn't support this property or method". Below is 'Plugin code' which I have in separate include & 'calling' code from test page.
    Thanks..

    <script src='../../foundation/javascripts/jquery.DN_JScript.js'> type="text/javascript"></script>

    (function ($) {
    // Shell for your plugin code
    jQuery.fn.listElements = function () {
    return this.each(function () {
    alert('SRC script/Tag Name:"' + $(this).attr("name") + '".');
    });
    }

    //$(document).ready(function () {
    // $("input").listElements();
    // $("p").listElements();
    //});
    alert("PLUGIN - list Elements");
    })(jQuery);
    .....................................................
    $(document).ready(function () {
    alert("Page call for PLUGIN - ListElement");
    $("input").listElements();
    $("p").listElements();
    });

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,191
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Hi dnendza and welcome to SitePoint,

    I have tested your code and it works as expected, can you please ensure the file isn't failing to load as it sounds like that is happening in your case.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •