Couldn’t find a clear answer to what I’m trying to achieve. I’m sure it’s simple but I’m missing it.
I will be building a list of links on a page that all have the class of “prettyLink” and each will have a title. On mouseover I’m trying to store that title in a variable and remove the title, then on mouseout replace that title with what was stored. (basically removing the title while being moused over and putting it back when moused out)
here is the code:
$('a.prettyLink').mouseover(function() {
var oldTitle = this.title;
$(this).removeAttr('title');
}).mouseout(function() {
$(this).attr('title',oldTitle);
});
Any help is appreciated. Thanks!
Simply declare the variable outside of the
mouseover()method:JS Fiddle demo.
Declaring the variable outside of the method allows the variable’s value to be assigned within the method, and have that new value be available elsewhere.