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.

Community
  • 1
  • 1
JacobTheDev
  • 17,318
  • 25
  • 95
  • 158

1 Answers1

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.

alex
  • 479,566
  • 201
  • 878
  • 984