2011-10-05 4 views
0

다음과 같이 jQuery 코드가 있습니다. 제가jQuery DOM 선택기 문제

document.getElementsByTagName ("A") [0] .getAttribute ("타겟")을 작성하는 경우

$("#"+iframeId).attr("src",url); //works perfect 
$("a[target="+iframeId+"]").attr("href", url); //does not return anything. not sure why? 

여기 iframeId 그것을, 방화범 관리자에서 "swcontent"

<a target="swcontent" href="xyz.html" class="standardMenu_on">Link</a> 

를 얻을 대상 "swcontent"를 찾지 못합니다

이제 JS가 포함되어 있습니다.

jQuery.extend = jQuery.fn.extend = function() { 
    // copy reference to target object 
    var target = arguments[0], 
     a = 1; 

    // extend jQuery itself if only one argument is passed 
    if (arguments.length == 1) { 
     target = this; 
     a = 0; 
    } 
    var prop; 
    while (prop = arguments[a++]) 
     // Extend the base object 
     for (var i in prop) target[i] = prop[i]; 

    // Return the modified object 
    return target; 
}; 

이 어떤 문제가 발생 할 수 그래, 어떻게이 문제를 해결할 경우 다음이 작동합니다

+1

는'iframeId' 확실히'swcontent'가 sorrounding와 경우가 완벽하게 작동? – lonesomeday

+0

예 ... 맞습니다 ..... – testndtv

답변

0

당신의 iframeId가 'swcontent'인 경우 (I 완전히 코드를 변경할 수있는 범위가 제한이있을 수 있습니다) 전 같은 당신이 하고 싶은 일을 간단한 예제를 준비하고 CSS 클래스가 실제로 앵커 태그에 추가됩니다

var iframeid = "swcontent"; 
$('a[target="' + iframeid + '"]').addClass('loadsInIframe'); 

여기를 체크 아웃 : http://jsfiddle.net/saelfaer/pWgWZ/1/

0

당신이 '와 vararible ;-)

$("a[target='"+iframeId+"']").attr("href", url); 
+0

내가 준 jQuery.extend를 고려 했습니까? – testndtv

+0

http://jsfiddle.net/WyB7q/ 참조 – reporter