I have a nicEdit (a rich editor) on my page and I'm inserting hyperlinks in the content of nicEdit via setContent() method after creating an instance of class nicEdit. It all works fine. However, some of the content have hyperlinks in them with a class of "someclass." I want to be able to catch the click events of those hyperlinks in the content of nicEdit using jquery. I tried, the following:

$('.someclass').click(function () { });
$('.someclass').on('click', (function () { });
$('.someclass').live('click', (function () { });
$('.someclass').bind('click', (function () { });

But nothing works. May be I'm going about it the wrong way as I really didn't get into the internals of nicEdit. Is it possible to insert hyperlink(s) (or any element) into the content of nicEdit and try to handle the click events (or any events) with jquery? If so any code sample is appreciated. Thanks in advance.

有帮助吗?

解决方案

I think I have something - I don't have all of your code for reference, but based on your clues, it seemed like this was fairly easy:

$(function(){

  var myEditor = new nicEditor({fullPanel : true }).panelInstance('editor');

  nicEditors.findEditor('editor').setContent(
      '<a class="someclass" href="http://www.google.com">Click Here</a>'
  );

    $('.nicEdit-main').on('click','.someclass',function(){
        alert('clicked');
    });
});

Fiddle Sample

If you want to do anything more specific, you can also pass the event to the click handler and act upon those in a normal fashion.

Let me know if this resolves your issues.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top