<ul class="Buttons">
<li><a href="#" onclick="myFunc(); return false;">Accept</a></li>
<li><a href="#" onclick="myFunc(); return false;">Reject</a></li>
<li><a href="#" onclick="myFunc(); return false;">On Hold</a></li>
<li><a href="#" onclick="myFunc(); return false;">Completed</a></li>
</ul>
In my script.js:
var myFunc = function () {
// I want to get the Text of the link e.g. if the first list item link is
// clicked, store "Accept" in a variable.
};
How can I achieve this?
You could pass the current link as argument to the function:
and then use the
innerHTMLproperty to fetch the text inside:UPDATE:
I haven’t noticed that actually your question is tagged with jQuery. In this case I would recommend you unobtrusively subscribing to the click handler:
and in a separate js file:
UPDATE 2:
It was asked how to assign those click handlers if those anchors were dynamically generated. So let’s assume that you start with the following markup:
and then when some event happens (click or something) you add an anchor dynamically:
where you have defined
myFuncsomewhere: