Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"setting a property that has only a getter"- javascript error with firefox

Up until recently, I had been using Safari 4 for testing and debugging my current jQuery Plugin. I tried my code out in Firefox and it started to complain about something within the JQuery-Framework: "setting a property that has only a getter". I tried to find out which line causes Firefox to complain and found that this happens somewhere here**

$.fn.util.create_$dom = function(opt) {
    var $dom = {};
    $.each(opt.dom,function(name,val){
        console.log(name);
        var $elm = $('<div>');
        $.each(opt.dom[name],function(_name,_val){
            if(_name == 'tagName') $elm = $('<'+_val+'/>');
        });
                    console.log(name+': ok');
        $.each(opt.dom[name],function(_name,_val){             **here       
            switch(_name){                                     **here
                case 'className': $elm.addClass(_val);         **here
                default: $elm.attr(_name, _val);               **here
            }                                                  **here
        });
        $dom[name] = $elm;
        console.log(name+': ok');
    });
    return $dom;
};

options.dom looks like this:

    dom:{
        wrapper:{className:'wrapper'},
        inner:{tagName:'p',className:'test',test:'bla'}
    },
like image 510
Julian Weimer Avatar asked Aug 08 '09 20:08

Julian Weimer


2 Answers

It looks like your trying to set the tagName of an element with this line

$elm.attr(_name, _val); 

This of course is not possible as it is read only.

like image 200
redsquare Avatar answered Oct 20 '22 16:10

redsquare


case 'tagName': break;

... is the solution, but in order to thank redsquare for the hint i marked him up.

like image 3
Julian Weimer Avatar answered Oct 20 '22 18:10

Julian Weimer