Share on Google+Share on Google+

Java Coder
document.getElementById
1 Answer(s)      4 years and 3 months ago
Posted in : JavaScript Questions

What is the use of document.getElementById method in JavaScript? Please provide a short example of this method in HTML.

Ads

View Answers

December 29, 2012 at 1:02 PM


JavaScript Tutorial - document.getElementById

document.getElementById is a method in JavaScript, which is used to accesses the first element with the specified id. Where ID is required. We can take a simple example of displaying date in a WebPage on button Click.

<!DOCTYPE html>
<html>
<head>
<script>
function displayDate()
{
document.getElementById("demo").innerHTML=Date();
}
</script>
</head>
<body>

<h1>Date Example in JavaScript</h1>
<p id="demo">click to Display Date.</p>

<button type="button" onclick="displayDate()">Display Date</button>

</body>
</html>









Related Tutorials/Questions & Answers:
document.getElementById
document.getElementById  What is the use of document.getElementById method in JavaScript? Please provide a short example of this method in HTML
JavaScript removeAttribute method
of an element. Most of the times it is used with the document.getElementById... removeAlignment(){ var read = document.getElementById("txt"... document.getElementById(), thereafter we can apply removeAttribute() method. Here
Advertisements
optimze page load - Java Beginners
(){ if (document.getElementById("page_txf") != null) { document.getElementById("page_txf").value = ; } setDisplayFilter(); //document.getElementById("searchList").focus
Javascript validation - Java Beginners
will be displayed. nameValue=document.getElementById(name).value; var re = /^\d{5}([\-]\d{4})?$/; if(nameValue == '' || nameValue == null ){ document.getElementById(msg).innerHTML='This field is Required'; document.getElementById(name
Line From code
Line From code  document.getElementById("demo").innerHTML=Date(); Please explain each and every word in this line
simple ajax Request and Response code...
==4) { // alert("visible"); document.getElementById("theResults").innerHTML=request.responseText; document.getElementById("theResults... { //alert("hidden"); document.getElementById("theResults").innerHTML
Javascript Loop Error - WebSevices
= document.getElementById('V_cname').value form.V_cperson.value = document.getElementById('V_cperson').value form.V_desgination.value = document.getElementById('V_desgi').value form.V_address.value = document.getElementById('V_address').value
Javascript background color - Java Beginners
if(document.getElementById('myName').style.backgroundColor=='rgb(254,204,204)') and if(document.getElementById('myName').style.backgroundColor=='rgb(254,204,204)') ...(){ if (document.getElementById('in').value=="amit"){ document.getElementById
wp-autolinker - Java Beginners
; document.getElementById('wp_autolinker_keyword_'+index).disabled = false; document.getElementById('wp_autolinker_target_url_'+index).disabled = false; document.getElementById('wp_autolinker_link_text_'+index).disabled = false
How to change focus among multiple select boxes?
= document.getElementById("list1").value; var option2 = document.getElementById("list2").value; var option3 = document.getElementById("list3").value; if(option1 != "") { document.getElementById("list2").selectedIndex = -1
Ajax - Ajax
) { if(document.getElementById("emp_id").value!="-1") { xmlHttp=GetXmlHttpObject() if (xmlHttp==null... Select Employee Id"); } } function stateChanged() { document.getElementById("ename").value =""; document.getElementById("emp_id").value
enabling and disabling a hyperlinks using javascript only
function disableLink() { document.getElementById('listOfOwners').disabled=true; document.getElementById('listOfOwners').removeAttribute('href'); document.getElementById('listOfOwners').style.textDecoration = 'none
java script - Java Beginners
hide() { if (document.getElementById) { document.getElementById('cancel
hide division - JSP-Servlet
showhide() { document.getElementById('div2').style.visibility = 'visible'; document.getElementById('div1').style.visibility = 'hidden'; } Hello World
Small clarification
Small clarification  This function is used to search and select particular word. In this function document.getElementById('d')); getElementById...(); textRange.findText("glitters"); textRange.select(document.getElementById('d
jsp code - Java Server Faces Questions
function inputtype(rad1) { var strValue=document.getElementById(rad1).value...=document.getElementById(rad1).value; alert(strValue); document.getElementById.... ============================================ document.getElementById("mydiv").innerHTML=strValue
Javascript Loop Error - WebSevices
locId = document.getElementById('cmbLocationVendor') if(locId != null) { form.V_location.value = document.getElementById('cmbLocationVendor').value...: " + Vendor); alert("Enter Vendor Name"); alert(document.getElementById('V
Combo box value Error - WebSevices
']); } document.frmProposal.hdVisa.value = document.getElementById('cmbVisa').value; Error... convert() { var val1 = document.getElementById("value1").value; var targetDiv = document.getElementById("target"); targetDiv.value
Urgent query about CreateTextFile using Javascript
("Scripting.FileSystemObject"); var write_id; write_id = document.getElementById('Name').value...(write_id, true,false); s.WriteLine(document.getElementById('Name').value); s.WriteLine(document.getElementById('Department').value); s.WriteLine
jsp help - JSP-Servlet
addRow(tableID) { var table = document.getElementById(tableID); var rowCount...); if(document.getElementById("psize").value>1) { document.getElementById("psize").value = document.getElementById("psize").value-1
Ajax not working in jsp
= document.getElementById("img" + txtField.id.substring(3) + "Error"); var btnSignUp = document.getElementById("btnSignUp"); if (!eval... = document.getElementById("btnSignUp"); var txtUID = document.getElementById("txtUID
javascript - Java Beginners
= document.getElementById('mainContainer'); var newDiv = document.createElement...(){ document.getElementById...').style.visibility='hidden'; document.getElementById('pro
Javascript & AJAX query - Ajax
validate() { var len; if(document.getElementById("psize").value...(document.getElementById("psize").value); } for(var i=1; i<=len; i++) { var person = "person" + i; if(document.getElementById(person).value
JavaScript Checkbox getElementById
. document.getElementById("image").style.visibility = 'visible'- This makes the image visible. document.getElementById("image").style.visibility = 'hidden'- This makes... showImage(){ if(document.getElementById('check').checked==true
ajax code with jsp - Ajax
= document.getElementById("tamt").value; var tenure = document.getElementById("tenure").value; var cal = tamt/tenure; document.getElementById("calid... total_amount = document.getElementById("value1").value; var tennure
how to set value of dropdown list
=== " ; } %> function setValue(h, m, a) { document.getElementById("hour").selectedIndex=h; document.getElementById("min").selectedIndex=m; document.getElementById("am").selectedIndex
how to set value of dropdown list
=== " ; } %> function setValue(h, m, a) { document.getElementById("hour").selectedIndex=h; document.getElementById("min").selectedIndex=m; document.getElementById("am").selectedIndex
Change background color of text box - Java Beginners
check(){ if (document.getElementById('in').value=="amit"){ document.getElementById('in').getAttributeNode('class').value="correct"; }else { document.getElementById('in').getAttributeNode('class').value="incorrect
Vendor Info Error - WebSevices
== 6 || pmMode ==1 || pmMode ==2 || pmMode =="" ) { document.getElementById... || pmMode ==""){ document.getElementById('vendorInfo').style.display="none"; } else { document.getElementById('vendorInfo').style.display="inline
java script - Ajax
(){ CommonService.getAmount(document.getElementById("pitems").value , populateAmount); } function populateAmount(data){ document.getElementById("amount").value=data...: function getValue(){ var combo = document.getElementById("sel
Java Script.
= document.getElementById("SearchCandForm"); var cbs = document.getElementById
Tutorials   
Java Spring Hibernate Struts Training code for programming How can I dynamically load user-entered data as content of jquery dialog? java webcam integration question java coding Fix Scrollbar position in a checkboxList after postback Information Save Alert Country wise redirection to files Interface in javascript connect database with javascript Zip Code ZipCode how to validate the email login How to play FLV video files on Ipad using HTML code or javascript code? Nitobi Grid is not working in IE10/IE11 jquery issue plese help RegEx Tree structure from json whose parents can be dragged and dropped from child newyorklife insurance getElementById not working javascript code for search in html file Implement The Skeleton Code Implement This Skeleton Code Mobile Automation using Appium Computer forensic application Java: Searching a string from doc files java linked list urgent !!! java linked list urgent!!! library management library management library management library management question Html form using JavaScript to display the table content java how to prevent no from unroundin off on clicking text box again in JSP and Jquery graph generation from xml design file display data from database in textbox when id entered in textbox Javascript Code for all fields how to get HTTP GET request value using javascript array Javascript Querry autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me Create SpreadSheet same as excel using java applet Create SpreadSheet same as excel using java applet How to change focus among multiple select boxes? Write JQUERY Code Write JQUERY Code Converting jsp variable to java variable java

Ads

 
Advertisement null

Ads