Eugen Soloviov
Eugen Soloviov

Reputation: 306

Jquery script doesn't work in IE 7-8

In IE 7-8 don't work script. Error on 3th string. I cant't find the error. From russian: "object don`t support this property or method".

Include in html:

<script type="text/javascript" src="{{ STATIC_URL }}js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.red-first.js"></script>

jquery.red-first.js:

(function($) {
    $.fn.redFirst = function() {
        var city = $(this).text().trim();
        var newCity;
        if (city == 'г. Москва') { city = 'Москва'; }
        if (city == 'г. Санкт-Петербург') { city = 'Санкт-Петербург'; }
        var cityWords = city.split(' ');
        if (cityWords.length == 1) {
            newCity = '<span class="red">' + city[0] + '</span>';
            newCity = newCity + city.slice(1);;
        } else {
            newCity = '<span class="red">' + cityWords[0] + '</span>';
            delete cityWords[0];
            newCity = newCity + cityWords.join(' ');
        }
        $(this).html(newCity);
        return this;
    };
})(jQuery);

$(document).ready(function(){
    $('#city').redFirst();
    $('#choose_reg_city').redFirst();
    $('#authorization #region').redFirst();
});

Upvotes: 0

Views: 733

Answers (1)

Jeff
Jeff

Reputation: 14279

string.trim() isn't a function that comes in IE. Other browsers define it but IE doesn't. Since you are using jQuery already use this instead:

var city = $.trim($(this).text());

Upvotes: 4

Related Questions