I got few onclick buttons inside li . I wonder how I can get the title of each button inside JavaScript function once it is clicked ?I want to set the title of button equal to a variable.Thanks in advance.
<javascript>
function MyFunction(MyFile,MyImage){
//here i want to get the title of onclick button which is Mango and set it equal to variable.
}
</javascript>
<li><a id="123456" onclick="setCurrentID('123456');javascript:MyFunction('type=fruit&day=friday','http://somesite.com/Image1.png');">Mango</a><img src="http://www.somesite.com/123456.png"></li>
<li><a id="123457" onclick="setCurrentID('123457');javascript:MyFunction('type=fruit&day=friday','http://somesite.com/Image2.png');">Apple</a><img src="http://www.somesite.com/123457.png"></li>
You send the id with the onclick function and then you reference the label via:
document.getElementById("myBtn").text;
So basically:
<a id="1" onClick="reply_click(this.id)">B1</a><br />
<a id="2" onClick="reply_click(this.id)">B2</a><br />
<a id="3" onClick="reply_click(this.id)">B3</a>
<script type="text/javascript">
var newText = 'Thank You';
function reply_click(clicked_id)
{
alert(document.getElementById(clicked_id).text);
document.getElementById(clicked_id).text = newText;
}
</script>
Edit: Apologies, didn't see you were using anchors instead of buttons as your question mentions, my fault. I also added how to change the text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With