How to get value of an element by class in javascript ?



How to get value of an element by class in javascript ?..

Answer / Sameer Dayal

To get the value of an element by class in JavaScript, you can use the `document.getElementsByClassName()` method and then access the value using the index or iterate through the returned NodeList.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More JavaScript Interview Questions

WHAT IS DIFFERENT BETWEEN CORE JAVA AND ADVANCED JAVA?

2 Answers  


What are 2 (shorthand) boolean operators supported by javascript

1 Answers  


i want to display time using hidden variable in a page,but when i click button that page that hidden variable loosing its value.i m sending the code also. <script type="text/javascript" language="javascript"> var tick=0; window.onload = function() { //debugger if(document.getElementById("hdnTicker").value != "") tick = parseInt(document.getElementById("hdnTicker").value); setInterval("Timer()",1000); } function Timer() { //debugger document.getElementById("hdnTicker").value = tick++; //alert(document.getElementById("hdnTicker").value); document.getElementById("lblTimeSpent").innerHTML = "0." + tick; if(tick == 30) { //message or redirect to result window alert('time is out'); //clearTimeout(); } } </script> <form id="form1" runat="server"> <div> <table> <tr> <td> <asp:Label ID="lblTimeSpent" runat="server" Visible="true" ForeColor="Blue" ></asp:Label> </td> <td> <%-- <asp:textbox EnableViewState="true" id="hdnTicker" runat="Server" style="visibility:hidden"></asp:textbox>--%> </td> </tr> <tr> <td> <asp:Button ID="btn" runat="server" Text="hi" OnClick="btn_Click" Height="30px" Width="60px" /> </td> </tr> </table> <%--<asp:HiddenField ID="txt" runat="server" Visible="true" />--%> </div> </form> <input type="hidden" id="hdnTicker" name="hdnTicker" enableviewstate="true" runat="server" />

1 Answers  


What is a string in javascript?

1 Answers  


What does the term sticky session mean in a web-farm scenario?

1 Answers  


Is it possible to use javascript to change the meta-tags of the page?

1 Answers  


How will you create new object in javascript?

1 Answers  


Which built-in method returns the characters in a string beginning at the specified location?

1 Answers  


Where do I write javascript code?

1 Answers  


How do I view javascript files in chrome?

1 Answers  


What are the ways to emit client-side javascript from server-side code in asp. Net?

1 Answers  


What is a good javascript editor?

1 Answers  


Categories