开发者

JQuery SetBubblePopup

Hey guys I have a weird error

I wrote this code against setbubblepopup

$(document).ready(function () { $('a').hover(function () {

        var tempID = $(this).attr("id");
        var tempTitle = $(this).attr("title");
        var totalID = ("'开发者_如何学Ca#") + tempID + ("'");

        console.log(totalID);

       $(totalID).SetBubblePopup({
            innerHtml: tempTitle
        });



    });

});

when I run it I get Selector expected. The console log show me 'a#thirdlink' so I am getting the correct format

When I put:

$('a#thirdlink').SetBubblePopup({
            innerHtml: tempTitle
        });

it works with no errors that's what is weird. When I use my var totalID it doesn't work and when I hard code it works.


You're adding an extra set of quotes in there, this:

var totalID = ("'a#") + tempID + ("'");

Should just be:

var totalID = "a#" + tempID;

This isn't a valid selector: $("'a#something'"), but this is: $("a#something") :)

Overall though, an ID should be unique in the page, you can just use $(this) instead of constructing a selector...if your IDs are unique, this already refers to the element you want, so this should work:

$(this).SetBubblePopup({ innerHtml: tempTitle });
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜