2013-04-30 3 views
0

그림 요소에 내 특집 이미지를 래핑했습니다. 그러나 IE8은 그림 요소를 제대로 인식하지 못하고 이미지를 멍청하게 만듭니다. 그래서 jQuery를 사용하여 IE8을 탐지하고 figure 요소를 간단한 div 요소로 대체하려고합니다.jQuery가 일치하는 요소를 다른 요소 태그로 바꿉니다

여기 내 테스트 jQuery의 :

jQuery('.entry figure.figureFeatured').replaceWith(
    jQuery('<div/>').html(
     jQuery('.entry figure.figureFeatured').html() 
     ) 
    ); 

그것은 복사 코드 아래

답변

0

사용 (크롬의 관리자에 따라) 원래 그림 요소의 속성이 더 이상 교체 된 div 요소에 부착 된 것을 제외하고 잘 작동 ... 너무 속성

jQuery('.entry figure.figureFeatured').replaceWith(
    var $div=jQuery('<div/>'); 
    $div.html(jQuery('.entry figure.figureFeatured').html()) 
    $div.attr(jQuery('.entry figure.figureFeatured').getAttributes()); 
    ); 
당신은

아래처럼 jQuery를에에는, getAttributes 기능을 추가해야합니다

(function($) { 
    $.fn.getAttributes = function() { 
     var attributes = {}; 

     if(this.length) { 
      $.each(this[0].attributes, function(index, attr) { 
       attributes[ attr.name ] = attr.value; 
      }); 
     } 

     return attributes; 
    }; 
})(jQuery);