Jump to content

Add title attribute


Recommended Posts

I have a word that will repeat itself a couple times and I want that on mouse hover (title) it display the definition. I think the best way is with JS unless you have a better idea.How would I do that?

JS:if(document.getElementById.id=='deprecated'){	document.deprecated.title='Deprecated definition';}HTML:<span id="deprecated">Deprecated.</span>

Link to post
Share on other sites

Why not just use the html title attribute:<p>I am <span style="text-decoration:underline" title="Depricated: blah blah blah">depricated</span> in a paragraph</p>

Edited by scott100
Link to post
Share on other sites

Because the text will be a definition which is a long sentence which I will repeat for every instance of the word deprecated. If ever I want to change something in the sentence or just remove it, it's a lot easier with JS I believe. Of course I could always do search and replace to modify the sentence.

Link to post
Share on other sites

you can only use a particular id once in an html document. Maybe you could use a class named "deprecated" instead of an id. Then you could loop through the elements of the document looking for matches to that class.if you want to just use the mouseover even like you were trying.. change it to thisjavascript

function setTitle(element){    element.title="A deprecated element or attribute is one that has been outdated";}

html

The applet element was <span class="deprecated" onmouseover="setTitle(this)" title="">deprecated</span> in HTML 4.01.

You could change the function to accept additional parameters so that it can work for more than one term. You could store definitions in an 2 dimensional array first column would be the term, second the definition... just make sure you change the function calls to match...if you use server-side scripting... you could just store the definition in a variable and print that variable into the title attribute of all the elements you need it in. If you need to make a change, just change the value of the variable.you could use style definitions to set the cursor, font color, background color, text-decoration, etc... to let the user know there is something different about that text...An alternative to using the mouseover would be to have the user click and get a popup that displays the definition in an easier to view format...

Link to post
Share on other sites

I will be using PHP for this project so I think the best way is with the variable (simple and easy). I'm just trying to create a template right now.It's awesome! it's a web programming site :)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...