Hi,
I have the followng HTML SPAN, I need to get the value within the Tags using class name. Please note I cannot use ID.
<span class="greeting">ASPSnippets provides best working solution.</span>
Hi makenzi.exc,
Use getElementsByClassName to select the elements having the specified class name.
Refer below example.
HTML
<html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css"> body { font-family: Arial; font-size: 10pt; } </style> </head> <body> <span class="greeting">ASPSnippets provides best working solution.</span> <script type="text/javascript"> function GetSelectedFruits() { // Referencing the Element using Class name. var greeting = document.getElementsByClassName('greeting'); alert(greeting[0].innerHTML); }; </script> <input type="button" value="Submit" onclick="GetSelectedFruits()" /> </body> </html>
Demo
Screenshot
Downloads
Download Sample
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.