0

Here I will be having title for an image and I need this title for other purpose. But I don't want that title to be displayed on hover of the image. Sooner reply will be appreciated. Thanks in advance.

2
  • If you want to use the title for other purpose , why not use user defined attribute in your tag? e.g. user-title=" " , etc. and get that attribute as $('anyid').attr('user-title');
    – Newinjava
    Jun 3, 2015 at 12:43
  • Maybe you should switch from title to alt-attribute? Not sure why you are needing a title.
    – Sabrina
    Jun 3, 2015 at 12:50

2 Answers 2

3

Don't apply it using the title attribute, but with a data attribute. That way the default behavior won't be invoked, but you will still be able to access it for your purposes.

<img data-title="Image Title" ...
0

If you can, move the title to data-title, that's a custom attribute that you can use for other purposes for your title.

If you can't, you could use a js like this

$("img").mouseenter(function(){

        // Get the current title
        var imgtitle = $(this).attr("title");     
        // Store it in a temporary attribute
        $(this).attr("data-title", imgtitle);     
        // Set the title to nothing so we don't see the tooltips
        $(this).attr("title","");

    });
    $(".element").mouseleave(function(){
        // get the attribute back
        var imgTitle = $(this).attr("data-title");
        // Set the title back
        $(this).attr("title","imgtitle ");             
    });

That ought to do the trick

Not the answer you're looking for? Browse other questions tagged or ask your own question.