Search code examples
jquerytinymceattr

TinyMCE and jQuery - attr() is returning an Object


I've solved this by using data() instead of attr(), but I'd still like to know if this is just me, and what's causing it:

I'm using jQuery 1.7.1 and TinyMCE 3.5b3 (jQuery package). No other JS libraries.

This code outputs "string", and the anchor tag's href, as expected, when the link is clicked.

$('a.page_item_delete').on('click', function(event){
    event.preventDefault();
    var $this = $(this);
    console.log(typeof $this.attr('href'));
    console.log($this.attr('href'));
});

When I activate TinyMCE on some textareas on the page, it outputs "Object" and, of course, attr() stops returning an expected value. I'm activating TinyMCE via:

$('textarea.tinymce').tinymce(options);

Has anyone else experienced this behaviour with TinyMCE? Is there a known bug, or workaround? Why is TinyMCE apparently affecting unrelated HTML elements on the page?


Solution

  • I am having the same problem. It is being caused by the tinymce-jquery package overriding the attr and css methods of the jquery object. It seems (sadly) that the solution is to not use the jquery version of tinymce.

    I haven't worked yet out why this wasn't a problem with jquery 1.6 and is a problem with 1.7.

    Edit:

    I was using the jquery plugin like this:

    $('.wysiwyg', '#EditForm').tinymce({
        -- SETTING HERE
    });
    

    and now I have done the following to replicate the behavior I required when using the jquery plugin:

    $('.wysiwyg', '#EditForm').each(function(){
        id = $(this).attr('id');
        var ed = new tinyMCE.Editor(id, {
        -- SETTINS HERE --          
        });
        ed.render();
    });
    

    Hope this helps