SitePoint Sponsor

User Tag List

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

    Question Get Elements by CSS selector question...

    So, I'm going to attempt to create a method for getting elements using a CSS selector. I'm starting with some basics - single selectors like #id, .class, and tag - descendant selectors like #id .class tag - combined selectors like #id.class - and group selectors like #id, .class, tag.

    My question has to do with selectors like "tag#id" or "#id1 #id2" or ".class tag #id" etc... Essentially where multiple ID's exist, or the single ID doesn't come first. Is there any reason not to simplify the process down to using a single ID?

    So for example:

    - "#id1 #id2" = document.getElementById("id2");
    - ".class tag #id" or "tag#id" = document.getElementById("id");
    - ".class #id tag" = document.getElementById("id").getElementsByTagName

    Are these assumptions correct?

    I hope I'm making sense!

    Thanks,
    Migs

  2. #2
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not look at the dozens out there, that people have been working and improving for months and years? Such as cssQuery? And if you can, improve upon those or learn how they were coded.

  3. #3
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I don't always understand the syntax and processes they use, and what I'm looking for is usually buried in hundreds to thousands of lines of code. Besides, I want to learn by practice so I can experience the faults and learn from my mistakes. Maybe it's backwards, but I hate to copy code without understanding what's going on.

  4. #4
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I hate copying code as well... I would suggest doing something easier. This is a pretty advanced topic, which may require knowledge of XPath and or regular expressions. I don't think you can get far without knowing either one of those.


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
  •