Search code examples
htmlinheritancetitle

HTML: stop Child elements from inheriting parent's [title] attribute


The issue is that when I declare a title attribute for a 'wrapper' element, the a tool-tip shows up when the cursor falls inside the 'content' element as well. How do I prevent this(inheritance) from happening?

<style> 
  #content{ margin:25px;}
</style>

<div id='wrapper' title='example'>
  <div id='content'>

  </div>
</div>

(I only want the tool-tip to show up between the edges of the 'content' and 'wrapper' elements, instead of in both)


Solution

  • I don't think this is possible with pure CSS or HTML.

    One way to hack this is using client side code.. basic plain JavaScript example:

    window.onload = function() {
        var oDiv = document.getElementById("content");
        oDiv.onmouseover = function() {
            this.parentNode.setAttribute("old_title", this.parentNode.title);
            this.parentNode.title = "";
        };
        oDiv.onmouseout = function() {
            this.parentNode.title = this.parentNode.getAttribute("old_title");
        };    
    };
    

    This will "clear" the parent div title upon mouse over of the contents, and restore the title when the mouse leave the contents.

    Live test case: http://jsfiddle.net/UASPZ/