Your Open Source

 
Related Posts

GetElementById or getElementByName Method

getElementById or getElementBy Name :

You can get the element values from the document by using getElementById() or getElementByName() function. Both functions get the element from the document.
Syntax:
          getElementById("element_id");

          getElementByName("element_name");

The Example as follows :-
<html>
    <head>
        <title>getElementByID() Method Example</title>
    </head>
    <body>
        <script>
            function changeIt(){
                var obj = document.getElementById("txt_content");
                obj.innerHTML = "You have clicked!";
            }
        </script>
        <div id="txt_content" onclick="changeIt()"> Click Here</div>
    </body>
</html>

  • hits 5058
  • datetime Oct 09 09 11:35:11
  • author Sekar
  • rating

Rating : 12345
Tags :- JavaScript

Answers

vaishali
Apr 20 10 09:41:26
It should be,
<html>

    <head>
        <title>getElementByID() Method Example</title>
    </head>
    <body>
        <script>
            function changeIt(){
                var obj = document.getElementsByName("div1")[0];
                obj.innerHTML = "You have clicked!";
            }
        </script>
        <div id="txt_content" onclick="changeIt()" name="div1"> Click Here</div>
    </body>
</html>

vaishali
Apr 20 10 09:39:15
The script does not work with
getElementByName("element_name");

dfdffd
Aug 31 09 03:14:55

vv
Jul 20 09 02:40:14
cvv

Your Name:
Your Answers :
<> is a code tag
Preview
Enter the verification code: