2013-07-02 1 views
0

다음 코드가 있습니다.IE7에서 HTMLDivElement를 확인하는 방법

if(data.constructor == HTMLDivElement) 

이제 IE7에는/HTMLDivElement가 지원되지 않습니다.

IE7에 대해 동일한 사항을 어떻게 확인합니까?

나는
if(HTMLDivElement != undefined) 

을 시도하지만 여전히 IE7에 오류가 있습니다.

+0

당신이 정말 jQuery를 사용하는 또는 jQuery로 태그를 지정 했습니까? – screenmutt

+0

실제로 저는 jQuery를 사용합니다 ... 그러나이 특정 줄을 추측하면 사용되지 않습니다 ... – testndtv

+1

jQuery를 사용하고 있다면 계속 사용하게 될 것입니다. 나중에 코드를 읽을 때 프레임 워크에서 떨어지면 두통이 생길 수 있습니다. 간단한'.length' 테스트가 도움이 될 것입니다. – screenmutt

답변

0

시도 :

if(data.constructor === document.createElement('div').constructor) 
+0

우 ~ ~ ~'downvote' 술을 피우는 누군가 !! –

0

당신이 jQuery를 사용하고 있기 때문에, 당신은 간단한 테스트를 사용할 수 있습니다.

$('div#id').length == 0 

요소가 존재하지 않는 경우에도 마찬가지입니다.

var isItDiv = $(data).is('div'); 

jsFiddle Demo : 당신은 단순히 jQuery의 .is() 방법을 사용 할 수

0

나는이 같은 간단한 종류의 일을했다
//Using plain DOM elements - no cheating 
var e1 = document.getElementById('elem1'); //<div id="elem1"> 
var e2 = document.getElementById('elem2'); //<button id="elem2"> 

//it does not even have to be in the DOM! 
var ce = document.createElement('div'); 

console.log($(e1).is('div')); //true 
console.log($(e2).is('div')); //false 
console.log($(ce).is('div')); //true 
0

:

if (data.tagName == 'DIV') { 
    // do something 
}