2

I need to disable the title value, so the hover doesn't show up, and still read its value. According to this StackOverflow question, the following should work:

    $("[title]").each(function() {
        $this = $(this);
        $.data(this, "title", $this.attr("title"));
        $this.removeAttr("title");
    });

Which does remove the title property, the only problem is, I can't for the life of me figure out how to read that data value. I know it's a simple question, but I'd really appreciate the help, the jQuery documentation didn't help me on this.

What I currently have is: var description = $(this).find("img").data(this, "title"); which doesn't work for some reason.

1 Answer 1

2

The code example you gave could be tidied up a bit with the latest jQuery versions...

You probably want something like this...

$('[title]').attr('title', function(i, title) {
    $(this).data('title', title).removeAttr('title');
});

This will assign the title attribute to the data store of each element with a title attribute, and then remove the title attribute of the element.

Then you can read an element's old title attribute with...

$('.something').data('title');

jsFiddle.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, that worked great :) I'll accept it in just a minute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.