开发者

jQuery $(this) Problem, wrong object

开发者 https://www.devze.com 2023-04-08 16:17 出处:网络
i using this code to show a title $(\".line\").mopTip({ \'w\':150, \'style\':\"overOut\", \'get\': $(this).attr(\"title\")

i using this code to show a title

$(".line").mopTip({
'w':150, 
'style':"overOut", 
'get': $(this).attr("title")
});

but as title I get the title of page... what do 开发者_StackOverflowI wrong?


You are using this inside the document window scope, that is why it returns the document title. To get the title of each line you have to loop over each one of them.

$(".line").each(function(){
    //inside the each the scope of this refers to the current line
    $(this).mopTip({
        'w':150, 
        'style':"overOut", 
        'get': $(this).attr("title")
    });
});


$(this).attr("title")

This gets the attribute "title" of the page, it always does when called in the document.

If the class "line" is the target, replace $("this") with $(".line")


For set content 'mopTip' use construction

... = $( setting.get ).html();

'get' - init in params.

And you code convert to

$( "Title of page" ).html();

In other words, in params 'get' must be selector... or function which return selector. Correct architecture of HTML-page. Or correct code of jQuery-plugin. Or wrap init to each().

0

精彩评论

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