Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE 11 Error: Object doesn't support property or method 'replace'

My jquery script, which otherwise works, throws an error in IE11:

Error: Object doesn't support property or method 'replace'

Can anyone tell me why?

Basically, the script just shows/hides divs and other content. It does this based on whether or not the link used to get to the page has a particular query string.

To see the error (and the code), just open the following link in IE11. (Script debugging has to be turned on.)

https://jsfiddle.net/rpt613/dp2kcL7v/

The code...

$(document).ready(function() {
var url = window.location.href
option = url.search(/[?]option=/gi);
    if (option != -1) {
        showContent();
        changeStyle();
        removeShowLink();
    } else {
        $('div.backToTaskList, div.spacer, div.backLink').css('display' ==
        'none');
    }
    });

function showContent() {
    $('.backToTaskList, div.spacer').hide();
    $('span.toggleTaskList').hide();
    $('#RelatedTopics').hide();
}

function removeShowLink() {
        $("body").each(function() {
            if ($(this).prop("id") == 'allTask') {
                $('div.backToTaskList:contains("Show More")').each(
                    function() {
                        $(this).html($(this).html().split(
                            "Show More").join(""));
                        $("span#pipe").remove();
                    });
            }
        });
    }
    /* Restyle h2 to match styling of h1*/

function changeStyle() {
    $("h2.programmingtask").css({
        "color": "#199bd8",
        "font-weight": "normal",
        "font-style": "normal",
        "font-size": "14pt",
        "font-family": "Verdana",
        "margin-top": "45px"
    });
    /* Replace text content of h2 element with its ID attribute*/
    var replaceWith = $("h2.programmingtask, h1.programmingtask").attr('id');
    $("h2.programmingtask, h1.programmingtask").text(replaceWith);
}
like image 567
user3968861 Avatar asked Aug 11 '26 23:08

user3968861


1 Answers

It's this line

$('div.backToTaskList, div.spacer, div.backLink').css('display' == 'none');

it should be

$('div.backToTaskList, div.spacer, div.backLink').css('display', 'none');

and that's an error in any browser, as jQuery tries to use string.replace on the arguments passed in css() and instead only receives a boolean.

like image 60
adeneo Avatar answered Aug 14 '26 18:08

adeneo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!