Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
29
rated 0 times [  34] [ 5]  / answers: 1 / hits: 43909  / 12 Years ago, fri, october 19, 2012, 12:00:00

I know jQuery is easy to get the value but how can i use Javascript only to get the value?



This is what I did



<input type=text class=num /> <a href=# onclick=alert(document.getElementsByClassName('num').value);> click </a>




thanks for help


More From » javascript

 Answers
21

document.getElementsByClassName returns an array of elements. You're looking for the first element in that array:



document.getElementsByClassName('num')[0].value;


Demo: http://jsfiddle.net/2vRCU/1/


[#82483] Wednesday, October 17, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaitlyn

Total Points: 421
Total Questions: 73
Total Answers: 100

Location: South Georgia
Member since Sat, Jul 25, 2020
4 Years ago
;