This Code isn't working with class can anyone help......?
<!DOCTYPE html> <html> <head> <title> ...... </title> <script type="text/javascript"> function test(){ var txt=document.getElementsByClassName("txt_name"); var error1=document.getElementsByClassName("msg_name"); if(txt.value==''){ error1.innerHTML="please enter your name"; } else{ error1.innerHTML=''; } } </script> <style type="text/css"> span{ color: orangered; } </style> </head> <body> <input type="text" class="txt_name" name="txt_name"> <span class="msg_name" /> </span><br> LastName:<input type="text" class="txt_name" name="txt_name"> <span class="msg_name" /> </span> <br> <input type="button" id="btn_click" name="btn_click" value="Click" onclick="test()" /> </body> </html