开发者

jQuery DOM selector issue

I have a jQuery code as follows;

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

Here iframeId gets "swcontent"

<a target="swconte开发者_如何学运维nt" href="xyz.html" class="standardMenu_on">Link</a>

In Firebug inspector, if I write

document.getElementsByTagName("a")[0].getAttribute("target") it does find the target "swcontent"

Now in one of my included JS, I have;

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;
};

Could this causes any issues and if yes, how do I fix this (I might have limited scope to change the code entirely)


if your iframeId is 'swcontent' then it should work i prepared a simple example doing the same you want to do and the css class is actually added to the anchor tag

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

check it out here: http://jsfiddle.net/saelfaer/pWgWZ/1/


It works perfectly if you sorrounding the vararible with ' ;-)

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜