First of all my question is, does a tag in html stores a value like input type = "text" does?
Secondly, I have a links like this let say:
<a href="#" >A</a>
<a href="#" >B</a>
<a href="#" >C</a>
I want to pass for each of the link their value let say A, B, C.
What i do is this:
<a href ="" onClick = "sendVal(this);">A</a>
<script type="text/javascript">
function sendVal(letter){
alert(letter);
}
</script>
But unfortunatelly i dont get A , but i get its href, how would i get the letter?? Any idea?
First of all my question is, does a tag in html stores a value like input type = "text" does?
Secondly, I have a links like this let say:
<a href="#" >A</a>
<a href="#" >B</a>
<a href="#" >C</a>
I want to pass for each of the link their value let say A, B, C.
What i do is this:
<a href ="" onClick = "sendVal(this);">A</a>
<script type="text/javascript">
function sendVal(letter){
alert(letter);
}
</script>
But unfortunatelly i dont get A , but i get its href, how would i get the letter?? Any idea?
Share Improve this question asked Jun 12, 2013 at 13:10 LulzimLulzim 9157 gold badges18 silver badges28 bronze badges 3- Must be pure JS or can you use Jquery ? – Neta Meta Commented Jun 12, 2013 at 13:11
- How do I use Jquery with that, i am not familiar with jquery at all :s – Lulzim Commented Jun 12, 2013 at 13:13
- 1 Who upvoted this highly-Google-available question? – Evan Davis Commented Jun 12, 2013 at 13:17
3 Answers
Reset to default 3try this.
<a href ="#" onClick = "sendVal(this.innerHTML);">A</a>
function sendVal(letter){
alert(letter);
}
<a href ="#" onClick = "javascript: sendVal(this.innerHTML);">A</a>
here you go as JS only
<a href ="" onClick = "sendVal(this);">A</a>
function sendVal(letter){
alert(letter.text);
}
If you want cross browser patibility i would really use jquery, otherwise you'll have to do lots of checks to see which to use.
If you are not limited to JS(as per client request) and this is a learning project you should really look at: jQuery
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745142751a4613505.html
评论列表(0条)