Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3217232
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:23:14+00:00 2026-05-17T15:23:14+00:00

I’m creating a simple jQuery editor, nothing complicated, and just can’t seem to find

  • 0

I’m creating a simple jQuery editor, nothing complicated, and just can’t seem to find out why the events do not work. See code below.

var $editor = $('<div>').addClass('editor')
      .insertBefore(this.$element)
      .append(this.$element);

var $b = $('<div>').addClass('button-wrapper')
       .appendTo($editor);
this.$element.css({height:this.opts.height,width:this.opts.width});
//Load up each button.
$.each(this.opts.buttons.split(' '), function(i, button)
{
 //If its an empty string keep going.
 if(button == '')return true;

 //Generate a button.
 $('<div>').data('buttonName', button)
     .addClass(button.toLowerCase())
     .click(clicked)
     .hover(hover, hover)
     .appendTo($b);
});

To go over it, simply, $element represents the textarea that I am using as the base element, $b represents the button wrapper, and $editor is the div to wrap around all of these things. When I append the buttons to $editor none of the events fire, however, when I append to document.body it works perfectly fine. For the record, the event clicked and hover are nothing special, just testers to see if the events are working.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:23:14+00:00Added an answer on May 17, 2026 at 3:23 pm

    I’ve rewritten your code a little bit, just to figure out what you’re doing. This seems to work for me, unless I didn’t understand what the problem is that you’re describing. The buttons react to hover as well as click events. Aside from writing the things you’re doing differently, there’s no substantial change in the code.

    I suppose there’s a chance that Val was right in that there may be other elements overlaying your buttons. You haven’t shown us your CSS, so it’s hard to tell what’s going on on your side.

    <html>
        <head>
            <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
            <style>
                .bold, .italic, .underline{ width: 50px; height: 20px; background: green; margin: 10px; }
            </style>
        </head>
        <body>
        <textarea class="demo">
        </textarea>
        <script type="text/javascript">
                jQuery(
                    function($)
                    {
                        (function($){
                            //Constructor to make a new editor.
                            function TEditor(element, opts)
                            {
                                //Load in the element.
                                this.$element = $(element);
                                this.opts = opts;
                                //Let the browser know the object is ready.
                                this.enabled = true;
                            }
    
                            //The actual editor class.
                            TEditor.prototype = {
                                display: function()
                                {
                                    var
                                        $editor = this.$element.wrap('<div class="editor" />').parent(),
                                        $b = $('<div class="button-wrapper" />').appendTo($editor);
    
                                    this.$element.css({height:this.opts.height,width:this.opts.width});
                                    //Load up each button.
                                    $.each(this.opts.buttons.split(' '), function(i, button)
                                    {
                                        //If its an empty string keep going.
                                        if(button == '') return true;
    
                                        //Generate a button.
                                        $('<div class="' + button.toLowerCase() + '" />')
                                            .data('buttonName', button)
                                            .appendTo($b)
                                            .click(clicked)
                                            .hover(hover, hover);
                                    });
                                },
                                enable: function()
                                {
                                    this.enabled = true;
                                },
                                disable: function()
                                {
                                    this.enabled = false;
                                },
                                validate: function()
                                {
                                    if(!this.$element[0].parentNode)
                                    {
                                        this.destroy();
                                        this.$element = null;
                                        this.options = null;
                                    }
                                }
                            }
    
                            //JQuery function extension.
                            $.fn.teditor = function(options)
                            {
                                options = $.extend({}, $.fn.teditor.defaults, options);
    
                                //On load create a new editor.
                                function get(ele)
                                {
                                    var editor = $.data(ele, 'editor');
                                    if(!editor)
                                    {
                                        editor = new TEditor(ele, options);
                                        editor.display();
    
                                        $.data(ele, 'editor', editor);
                                    }
                                    return editor;
                                }
    
                                //Initialize.
                                this.each(function(){get(this);})
                                return this;
                            };
    
                            $.fn.teditor.defaults = {
                                buttons: 'Bold Italic Underline',
                                height: '150px',
                                width: '500px'
                            };
    
                            function clicked(e)
                            {
                                alert(e);
                            }
                            function hover(e)
                            {
                                console.log('hover');
                            }
                        })(jQuery);
    
                        $('.demo').teditor();
                    }
                );
            </script>
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.