473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Show text on Hover

Is there a way to increase the amount of time a hyperlink title
displays or show the desired text using javascript?

<a title="This is the title text displayed on hover.">Displayed
Text</a>

The above HTML will display the title text when the mouse is hovered
over the displayed text but it disappears quickly.

There may be a better way to display text on hover using javascript but
I do not know how.

Sep 22 '05 #1
7 77330
i wrote this a while ago, hope it helps

<script>
function hide_tooltip(){
document.getElementById("tooltipper").style.left=0
document.getElementById("tooltipper").style.top=0
document.getElementById("tooltipper").style.width= 1;
document.getElementById("tooltipper").style.height =1;
document.getElementById("tooltipper").innerHTML="" ;
}
function show_tooltip(event,txt){
document.getElementById("tooltipper").style.left=e vent.clientX+20
document.getElementById("tooltipper").style.top=ev ent.clientY+30
document.getElementById("tooltipper").style.width= 300;
document.getElementById("tooltipper").style.height =150;
document.getElementById("tooltipper").innerHTML=tx t;

}

</script>

<a href=# onmouseover="javascript:show_tooltip(event,'damn') "
onmouseout="javascript:hide_tooltip()" style='color:red'>link</a>";
<div id='tooltipper'
style='position:absolute;left:0;top:0;width:1;heig ht:1;border:1px solid
black;background-color:rgb(250,250,255)'></div>

Sep 22 '05 #2
Matt wrote:
Is there a way to increase the amount of time a hyperlink title
displays or show the desired text using javascript?

<a title="This is the title text displayed on hover.">Displayed
Text</a>

The above HTML will display the title text when the mouse is hovered
over the displayed text but it disappears quickly.

There may be a better way to display text on hover using javascript but
I do not know how.


JavaScript has no control over how long tool tips are displayed for, or
even whether they are displayed at all. It is common for browsers to
show a tool tip where an element has an alt or title attribute value,
but that is not consistent across all browsers.

There are some pseudo tool-tip scripts at the link below, but they may
be a bit over the top (beware of pop ups when entering the site).

<URL:http://www.walterzorn.com/tooltip/tooltip_e.htm>

I'm also not fond of tool tips that follow the cursor, they become an
annoyance.

You might want to poke around quirksmode.org, it has all you need to
know about cursor and element position so that you can build your own
'tool tip' that works in most browsers:

Cursor position:
<URL:http://www.quirksmode.org/js/events_properties.html>

Element position:
<URL:http://www.quirksmode.org/js/findpos.html>


--
Rob
Sep 22 '05 #3
ASM
Matt wrote:
Is there a way to increase the amount of time a hyperlink title
displays or show the desired text using javascript?

<a title="This is the title text displayed on hover.">Displayed
Text</a>

The above HTML will display the title text when the mouse is hovered
over the displayed text but it disappears quickly.

There may be a better way to display text on hover using javascript but
I do not know how.


working with only css on "normal" browser
and with JS in IE
try this (title replaced by a span in link text :

<html>
<a href="#here" id="here">Displayed Text
<span>This is the <strong>title text</strong> displayed on hover.
<br>And I can add some lines if I want
<br><em>Only if I use tag</em> <tt>&lt;br&gt;</tt>
<br>
<br>Tag <tt>&lt;P&gt;</tt> is absolutly <u><b>forbiden</b></u> here
</span>
</a>

<style type="text/css">
a { position: relative; text-decoration: none; }
a span { display: none; position: absolute;
border: 1px solid blue; color: blue;
background: #ff9; padding: 5px;
font-family: geneva, arial, verdana;
}
a em { color: red }
a tt { color: black; font-size: 1.5em; }
a:hover { background: yellow }
a:hover span { display: block }
</style>

<script type="text/javascript">
// script to put in all end of page
function roll(theLink) {
if(theLink.getElementsByTagName('SPAN')) {
var a = theLink.getElementsByTagName('SPAN')[0];
a.style.display = a.style.display==''? 'block' : '';
}
}
function setIE() {
var L = document.links;
for(var i=0;i<L.length;i++) {
L[i].onmouseover= function(){roll(this);};
L[i].onmouseout= function(){roll(this);};
}
}
var ie=false; /*@cc_on ie=true; @*/
if(ie) setIE();
</script>
</html>
--
Stephane Moriaux et son [moins] vieux Mac
Sep 22 '05 #4
ASM
pipe wrote:
i wrote this a while ago, hope it helps


I have that (working on click) :

http://perso.wanadoo.fr/stephane.mor...yers_click.htm
--
Stephane Moriaux et son [moins] vieux Mac
Sep 23 '05 #5
ASM wrote:
pipe wrote:
i wrote this a while ago, hope it helps

I have that (working on click) :

http://perso.wanadoo.fr/stephane.mor...yers_click.htm


Not in Firefox - clientX/Y are for IE and sycophants. Try the
following, it finds the cursor position using the quirksmode reference I
quoted earlier:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Demo</title>

<style type="text/css">

..toolTip {
border: 1px solid #999999;
background-color: #dddddd;
position: absolute;
padding: 1px 5px 1px 5px;
}

..buttonSet {
font-family: arial, sans-serif;
color: #336699;
background-color: #ffffff;
float: left;
border: 1px solid #999999;
}

</style>

<script type="text/javascript">

// The tool tip is created and referenced as a global object
var tipDiv;
function genToolTip()
{
if (document.createElement) {
tipDiv = document.createElement('div');
document.body.appendChild(tipDiv);
tipDiv.appendChild(document.createTextNode('initia l text'));
tipDiv.className = 'toolTip';
tipDiv.style.display = 'none';
}
}

window.onload = genToolTip;

function showTip(e, txt)
{
if ( tipDiv ) {
var e = e || window.event;
var xy = cursorPos(e);
tipDiv.firstChild.data = txt;
tipDiv.style.left = (xy[0] + 5) + 'px';
tipDiv.style.top = (xy[1] + 15) + 'px';
tipDiv.style.display = '';
}
}

function hideTip()
{
if ( tipDiv ) {
tipDiv.style.display = 'none';
}
}

// Based on quirskmode 'get cursor position' script
function cursorPos(e){
if (e.pageX || e.pageY) {
return [ e.pageX, e.pageY ];
} else if (e.clientX || e.clientY) {
return [
e.clientX + document.body.scrollLeft,
e.clientY + document.body.scrollTop
];
}
}

</script>

</head>
<body>
<div>
<a href="#"
onmouseover="showTip(event,'customisable tool tip')"
onmouseout="hideTip()">Mouse over the tip</a>
</div>
</body></html>
--
Rob
Sep 23 '05 #6
Matt wrote in message news:11**********************@g49g2000cwa.googlegr oups.com...
Is there a way to increase the amount of time a hyperlink title
displays or show the desired text using javascript?

<a title="This is the title text displayed on hover.">Displayed
Text</a>

The above HTML will display the title text when the mouse is hovered
over the displayed text but it disappears quickly.

There may be a better way to display text on hover using javascript but
I do not know how.


food for thought:

If someone has javascript disabled or browses with a non javascript
capable browser, you might want to keep those title attributes.

A neat solution would be to create a function which checks if the
underlying element contains a title then display it via javascript
removing at the same time the title attribute. On onmouseout,
adding the title attribute back and hiding the displayed tooltip.

I'm not sure if removing the title attribute is necessary, or if
displaying the tooltip text through onmouseover would suffice,
but somehow I doubt the latter.
This way, if a browser doesn't javascript, the tooltip title is still
being displayed.

Sep 23 '05 #7
ASM
RobG a écrit :
ASM wrote:
I have that (working on click) :

http://perso.wanadoo.fr/stephane.mor...yers_click.htm

Not in Firefox


I don't know , but ... it seemed to works on mine
- clientX/Y are for IE and sycophants.
well, that's true, I'd forget pageX pageY :-(
Try the
following, it finds the cursor position using the quirksmode reference I
quoted earlier:


thank you, it is on my HD (for next time ?)

--
Stephane Moriaux et son [moins] vieux Mac
Sep 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Michael Skind | last post by:
Hello, I use a simple Table : <TABLE> <TR 1> <TD></TD> </TR> <TR 2> <TD></TD> </TR>
1
by: Dirk Reske | last post by:
Hello, i'm looking for a way to show formatted text and images (e.g. animated gif's) in an edit control... like in many chat programs does somebody know how to make this? thx *** Sent via...
0
by: mahsa | last post by:
hi, do you have any idea how can I show some text on image button that show in datalist?
2
by: Guoqi zheng | last post by:
Dear sir, I am using the default paging function of datagrid. Below is my code. <PagerStyle NextPageText="&gt;&gt;&gt;" PrevPageText="&lt;&lt;&lt;" HorizontalAlign="Center" Mode="NumericPages"></PagerStyle> ...
1
by: Tor Inge Rislaa | last post by:
Toolbar doesn't show text I have a toolbar on top of my form. The .text property is set for each button, but it is visible only in design mode. When I run my application the text is invisible....
2
by: UJ | last post by:
Is there a way with a asp:checkbox to run a JavaScript to display/hide text/input on the screen without doing a postback? I also need to be able to access the stuff at the server so I need to...
4
by: devine | last post by:
Hi All, I am VERY new to Javascript. I have been provided with some code, which will enable me to hide/show a text area and change a submit button dependant on a check box. <!DOCTYPE html...
1
by: pankajprakash | last post by:
Hi, i want to show the page numbers in gridview control's with a text such as Page : 1 2 3 4 I just have to show the "Page" text before the number, what should i do.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.