Click to See Complete Forum and Search --> : Dynamically Change Image Title


aruzinsky
May 16th, 2005, 06:33 PM
Consider the following HTML:

<img ... title = "text" >

I want to change this "title" on an event, preferably using Javascript.

PramodsNair
May 23rd, 2005, 04:38 AM
Ok use the below given code snippet
STep 1 :
Place an image and a button

<img src="BB.bmp" title = "Image 1" id ="A1">

<button onclick="chT()">Change Img Title</button>

Step 2:

Write the function chT() which is called from the onClick event of Button
<script>
function chT()

{
document.all.A1.title = "Image 2"
}
</script>

Hope this is of help to you

Dr. Script
May 23rd, 2005, 03:56 PM
Few revisions to better the code:

(1) Have your image and a button:<img src="logo.png" title="Logo" id="logo">

<button onclick="chngTitle('logo','New Title')">Change Img Title</button>(2) Add this code:<script type="text/javascript">

function chngTitle(id,ttl) {
document.getElementById(id).title = ttl;
}

</script>That's cross browser and universal (can be used more than once to do a similar task).

Dr. Script

aruzinsky
May 24th, 2005, 10:52 AM
Thank you both very much!