SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2007
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating JQuery button plugin

    Hi, I just created a simple button plugin with jQuery and met a little issue which I can't figure out where is the problem. What the plugin does is, it will create buttons based on a div title attribute, for example:

    <div title="button1|button2|button3">

    So in this case, 3 buttons will be created. The plugin will also add in mouse events (hover, mousedown, etc) to addClass/removeClass for each button. But the issue here is whenever I mouseover button1 or button2, only button3 seems to have the mouse event registered.

    An example can be view here:
    http://jsfiddle.net/bEcD2/1/

    Any help is greatly appreciated.
    I Dunno LOL \(_o)/

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2007
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for reading people! I managed to got it to work by removing the button variable
    I Dunno LOL \(_o)/

  3. #3
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,198
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Good to hear you got it working but i found a lot of room for improvement such as assigned events using the .on() method which uses event delegation and considered best practice when using jQuery, see the following fiddle which i update from your link so you can see the improvements.

    http://jsfiddle.net/chrisupjohn/bEcD2/3/

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2007
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow neat!! Thank you very much chris! I've changed to using your .on version.
    I Dunno LOL \(_o)/

  5. #5
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,198
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    No problem, i just realized I may a very tiny mistake though which didn't allow one of the spans to append to the button. See the updated link http://jsfiddle.net/chrisupjohn/bEcD2/5/


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
  •