Question

I keep getting "Object doesn't support property or method" for basic jQuery such as "before". I'm trying to simply add a couple of DIV tags before an element. This works with iPhone, Android and responsive design view in Firefox but this particular phone in question, Nokia Lumia 520 keeps reporting "Object doesn't support property or method". Client suspects it's jQuery version which is version 1.4.3 (I know it's old but clients CMS isn't as simple as changing the jQuery version, it requires major upgrades on their side).

One thing I have noticed is that it does work if I setTimeout() for 4 seconds. So this made me think maybe the element isn't available or maybe the DOM is loaded differently on Windows phone. So I've tried various things such as $('#myelement').length, $(window).load(), waitUntilExists() (http://javascriptisawesome.blogspot.co.uk/2011/07/faster-than-jquerydocumentready-wait.html), even coding my own timer to check if the element exists every X milliseconds but still getting the error. $('#myelement').length always reports the element exists but I can't use for example $('#myelement').before('<div class="newDiv"></div>');. Any help much appreciated!

EDIT: Example code:

function initRWD(m){
    var t = setTimeout(function(){
        if($(m).length){
            $(m).before('<div class="newdiv"><div class="newdiv-inner">Hello</div></div>');
            clearTimeout(t);
        } else
            initRWD(m);
    },500);
}

$(document).ready(function(){
    //setTimeout(function(){
    initRWD('#myelement');
    //},4000);
});
Was it helpful?

Solution

I had one last go and figured it out! I added &&'before' in $(m) to the "if" statement as an additional check to see if the 'before' function/property/method exists also.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top