Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6732543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:39:48+00:00 2026-05-26T10:39:48+00:00

I am using vTip plugin to display titles on hover , here is my

  • 0

I am using vTip plugin to display titles on hover , here is my example code:

http://jsfiddle.net/bnjSs/

I have a Div#showTitles , When i click on it I wants to toggle display of all div.vtips titles on page just like mouseover.

$("#showTitles").click(function(){
  // this I am not sure how to acheive.  
  return false;
});

UPDATE:
http://jsfiddle.net/bnjSs/2/
I have tried this but its not showing on correct positions as mouseover but once i mouseover on .vtip and then i click on #showTitles its working fine, I also need to toggle this behavior :

$("#showTitles").click(function(e,ui){

this.xOffset = 5; 
this.yOffset = 10; 
this.top = (e.pageY + yOffset); 
this.left = (e.pageX + xOffset);

  $('.vtip').each(function(index) {
    title = $(this).text();
    $('body').append( '<p id="vtip"><img id="vtipArrow" />' + title + '</p>' );

        $('p#vtip #vtipArrow').attr("src", 'images/vtip_arrow.png');
        $('p#vtip').css("top", this.top+"px").css("left",  
   this.left+"px").fadeIn("slow");

 });
   return false;
 });

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:39:49+00:00Added an answer on May 26, 2026 at 10:39 am

    IDs should be unique.finished
    I’ve modified your current code to get it work under the current conditions. The function logic should be obvious because of the descriptive names. Fiddle: http://jsfiddle.net/bnjSs/7/

    Update: Added show/hide text + feature to the code, as requested at the comments.
    Update2: Taken care of whole code, improved efficiency.

    You’re overusing this. this.xOffset = 5 attaches xOffset to the element. Use var xOffset = 5 to define xOffset in the scope of the function. The code below has the following scope model:

    $(document).ready(function(){
       // Variables defined using `var` can be read by
       //   any function defined within this function
       function vtip(){
          // variables declared here can be read by any function defined inside vtip
          // but cannot be read by methods outside vtip
          function(){..} at .hover and .mousemove
             // These functions also have an own scope, and variables defined using
             // var cannot be read by anything outside these functions, even at vtip
       $("#showTitles").click(function(e){
          // variables declared here cannot be read by code outside this function
          // This function can read any variable which is declared using var at
          // $(document).ready
    

    Note: “Declare” means “Define using var“.

    Final code:

    // Run when the DOM is ready
    //Note: $(function(){ is short for  $(document).ready(function(){
    $(function(){
        var xOffset = 5; // x distance from mouse
        var yOffset = 10; // y distance from mouse
        var frozen_vtip = false; //Define it
        var vtip = function() {    
    
            $(".displaytip").unbind().hover(    
                function(e) {
                    if(frozen_vtip) return;
                    this.t = this.title;
                    this.title = '';
                    var top = (e.pageY + yOffset);
                    var left = (e.pageX + xOffset);
    
                    $('<p class="vtip"><img class="vtipArrow" src=""/>' + this.t + '</p>').css("top", top+"px").css("left", left+"px").fadeIn("slow").appendTo(this);
    
                },
                function() {
                    if(frozen_vtip) return;
                    this.title = this.t;
                    $("p.vtip", this).fadeOut("slow").remove();
                }
            ).mousemove(
                function(e) {
                    if(frozen_vtip) return;
                    var top = (e.pageY + yOffset);
                    var left = (e.pageX + xOffset);
    
                    $("p.vtip", this).css("top", top+"px").css("left", left+"px");
                }
            );  
        };
        vtip();
    
    
    // Second function, when text is "Hide titles" it should
    // prevent runing vtip() on mouseover (above function) and
    // when text is  "Show titles" It should normally run vtip()
    // (mouseover display title.
    
        $("#showTitles").click(function(e){
            e.preventDefault();
            if($(this).text() == "Hide titles"){
                $(this).text("Show titles");
                $('p.vtip').fadeOut("slow").remove();
                $('.displaytip').each(function(){
                    this.title = this.t; //Re-attach `title`
                });
                frozen_vtip = false;
            } else {
                frozen_vtip = true;
                $(this).text("Hide titles");
                $('.displaytip').each(function(index) {
                    if($('p.vtip', this).length) {return;}
                    this.t = this.title;
                    this.title = '';   
                    var $this = $(this);
                    var offset = $this.offset();
                    var height = $this.height();
                    var top = offset.top + height;
                    var left = offset.left + height;
                    $('<p class="vtip"><img class="vtipArrow" src="images/vtip_arrow.png" />' + this.t + '</p>' ).appendTo(this).css("top", top+"px").css("left", left+"px").fadeIn("slow");
                });
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,
I am using the Vtip plugin to show title values in a tooltip when
Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
Using online interfaces to a version control system is a nice way to have
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using VS2008, C#, .Net 2 and Winforms how can I make a regular Button
Using jQuery, what's the best way to automatically initialize a plugin on all current
Using a Microsoft version of SQL, here's my simple query. If I query a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.