SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2008
    Location
    South Florida
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Suppress title popup

    Does anyone know how to suppress the popup the browser will display on an element with a title attribute?

    I have a jQuery lightbox in my page and I use the title attribute to display a caption for each lightboxed image. but I don't want it to display in the browser when a user mouses over the thumbnail.

    Any ideas?

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,597
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Probably the simplest way would be to have the JavaScript loop through all the tags in the page and remove the content of all the title attributes so that they effectively read title=""

    Removing the attributes would work except for a bug in IE where images copy the alt attribute into the title attribute if a title attribute isn't specified. Setting the value to nothing will avoid that bug.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2008
    Location
    South Florida
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would that have an effect on performance?

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,597
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    It would depend on how frequently you want to turn the titles on and off and also on how you decide to implement it. You could also do part of the processing server side generating a JavaScript array of all the titles and references to all of the tags server side before delivering the page to the browser so as to make the processing faster (or build the JavaScript manually to match the page).

    If you gave each tag with a title an id and had all the ids in an array then you could simply loop through that array changing all the titles to nothing and then loop through it again to put all the titles back (from a second array) when you want them to work again. That would keep the performance hit from the extra processing to a minimum even of you need to use JavaScript at the end of your page to scan the content and build the arrays in the first place.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Evangelist
    Join Date
    Apr 2008
    Location
    Dublin, Ireland
    Posts
    461
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it's only a small number of elements or even just one then I would set the title = "" onmouseover and back again onmouseout.

    Code:
       var mylink = document.getElementById("mylink");
       mylink.onmouseover = function()   {
          this.htmlTitle = this.title;
          this.title = "";
       }
       mylink.onmouseout = function()   {
          if (this.htmlTitle) this.title = this.htmlTitle;
       }


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •