Results 1 to 2 of 2
  1. #1
    WTF Groupie Array
    Join Date
    Dec 2011
    Posts
    270
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Elements use the javascript

    How to Accessing Elements using javascript?

    Trekking in uttarakhand ,camping in uttarakhand ,wildlife in uttarakhand

  2. #2
    WTF Groupie Array
    Join Date
    Oct 2011
    Posts
    349
    Thanks
    0
    Thanked 2 Times in 2 Posts


    in accessing an element with an id attribute you can use document.getElementById

    HTML Code:
    <p id="p1">Paragraph 1</p>
    <p id="p2">Paragraph 2</p>
    <p>Paragraph 3</p>
    
    <script type="text/javascript">
    
    var p2 = document.getElementById('p2'); // this will return the paragraph tag with the id of p2
    
    </script>
    in accessing elements by their tag name you can use document.getElementsByTagName

    HTML Code:
    <p id="p1">Paragraph 1</p>
    <p id="p2">Paragraph 2</p>
    <p>Paragraph 3</p>
    
    <script type="text/javascript">
    
    var paragraphTags = document.getElementsByTagName('p'); // this will return an array of all the <p> elements
    
    </script>

    you can refer to this page for more information: https://developer.mozilla.org/en-US/...cument#Methods

    please note that the link is for gecko based browsers which are also used in different browsers sometimes other browsers have their version of a function


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •