jQuery $(this) Problem, wrong object
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().
精彩评论