SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    browser own name/id/thing on objects

    hi there people!.. im new to this forum

    here my question..
    is there some parameter that the browser add to an object like a unique name/code or something that we could access.

    i mean.. we have a Div with an Id, so to get the div we use getElementById('something')

    so my question is that if we dont set an Id to that Div.. the browser identify the div with something?

    :D

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi, welcome to the forums.

    What would the browser do with such information? The only thing that is similar to what you are describing is microformats.

    The browser doesn't add anything to HTML elements. Browsers do add certain properties and methods to HTML element objects that are sometimes standards-based and other times not. For example, Internet Explorer has the currentStyle property that no other browser implements.

    However, you're not being terribly clear about what it is you're after.

  3. #3
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey raffles!

    the idea behind this is saving characters to download by writing the id of element in the html
    insted of that... im wondering if the browser gives the objetcs something unique we can use

  4. #4
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,751
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, if there's no id, the element can potentially be obtained through its relations to other elements. Your HTML document is basically a tree in structure, well, an upside down tree to be exact.

    It starts at the root, and expands into different branches (nodes). Each branch can have other branches growing from it, on and on. There's a few types of relations: parent, child, sibling.

    In the case of parent, it would be say, the branch that a branch is growing from, or in an actual html document:

    <div><ul></ul></div>

    The ul would have the div for the parent. In the case of a child, it would be branches growing from the current branch, or in the case of the above, the ul would be a child of the div tag. For a sibling, it would be branches that grow from the same branch that the current one is growing from. So to expand the previous example:

    <div><h1></h1><ul></ul></div>

    The ul and h1 tags are both siblings, as they share the same parent (the div). So if we had a document like so:

    <html><body><div><h1></h1><ul></ul></div></body></html>

    We don't have an id to grab the ul right away, but we can traverse down using relationships to find it:

    document.body.firstChild.firstChild.nextSibling;

    so we start at the document's body, get the first element that is a child of the body (the div), get the first element that is a child of the div (the h1), then get the next element that is a sibling of the h1 (ie. it shares the same parent, being the div), which results in us getting the ul element.

    Another way you can find an element is through getElementsByTagName. This retrieves a list of tags, then you can go through each tag and look for a certain attribute that makes it stand out, such as a css class, or a style of some sort.

  5. #5
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I see what you mean now. I think you'd probably benefit from reading a tutorial on the DOM, such as this one.


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
  •