<div id ="testing"> <a id ="test1" href="www.xxx.com" onmouseover=greeting('test1')>Hello</a> <a id ="test2" href="www.yyy.com" onmouseover=greeting('test2')>Bye</a> </div> to change the innderHTML of the 2 links inside <div> I will have to have the following in the function I called for the event onmouseover. document.getElementById('test1').innerHTML = 'good morning'; document.getElementById('test2).innerHTML = 'have a great day'; Is there any way I can change them without having id in the <a>..</a> at all? I have a lot of links on this particular webpage.
What I understand is you need to do bulk changing in links' captions. I could not fuly follow because I cant see code of function greeting. Let me know if it is not what you want. Or post the exact scenario what needs be implemented. regards
Yes. that is what I want. function greeting(id) { document.getElementById(id).innerHTML = "something else"; } But I have tons of links inside the <div id="testing'><div> It will be too much pain to add an id to each individual <a></a>
How do I create the array? I thought about it but don't know how to refer the links inside the <div>. Basically I just need to change the text between<a href=...>text</a> when mouseover. But I have a lot of them and I just need to change some of them but still a lot.
Try this method. <script> function ABC(id,txt) { id.innerHTML = txt; }</script> <a onmouseover="javascript:ABC(this,'Link 1 text changed')">Link1</a> <a onmouseover="javascript:ABC(this,'Link 2 text changed')">Link2</a> <a onmouseover="javascript:ABC(this,'Link 3 text changed')">Link3</a> HTML: I hope it helps. regards
Thank you so much. It did the trick I want. I never understand the "this" thing for it. Any place I can read more about how to use "this"? Again, thank you very much.
At any event when you use the keyword 'this', it actually points to the current object. in simple words, 'this' means 'me', so whatever kind of object you are creating event handler for, 'this' will always poin to itself. Glad it helped. regars