SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Jul 2008
    Location
    Port Elizabeth, South Africa
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    2 ID's ok if one in a td?

    Hi - I know I can't have the same id twice on one page but it's working when one is in a td and one in a div, like this:

    <table>
    <tr>
    <td id="btmnav">
    <a href="http://amzn.to/VNNoXQ" target="_blank">Click here to see the best deals in Water Ionizers at Amazon</a>
    </td>
    </tr>
    </table>

    <div id="btmnav"><?php include("$rpath/1cde/btmnav.php"); ?></div>

    Is this okay? You can see it in action here:

    ==> http://www.greensmoothie.com/zshop/vwater.php

    (The tables are a relic from the distant past. They're staying on the page. I know they shouldn't be there. One day when time stops running away from me, I'll remove them.)

    thank you! - Val

  2. #2
    SitePoint Zealot RyanKing1809's Avatar
    Join Date
    Oct 2011
    Location
    Melbourne, Australia
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No. ID's are for single unique elements. If you want to specify an ID to style many elements you should be using the 'class' attribute - exactly like what you've done for your website (I cant see any duplicate ID's but I can see duplicate classes).

    For example this would be acceptable - however it is odd to assign the same class name to different tags. I think you would typically want same classes to both be either <td> or <div>, one or the other but not both. I don't think there's anything saying it's not allowed but it will make things easier to code & understand.
    HTML Code:
    <table>
    <tr>
    <td class="btmnav">
    <a href="http://amzn.to/VNNoXQ" target="_blank">Click here to see the best deals in Water Ionizers at Amazon</a>
    </td>
    </tr>
    </table>
    
    <div class="btmnav"><?php include("$rpath/1cde/btmnav.php"); ?></div>
    Reading this should help explain it a bit better than i can:
    http://css-tricks.com/the-difference...-id-and-class/

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,824
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Consider if you have two of the same id in your page then which of then should <a href="#btmnav"> jump to? Wich one should a JavaScript getElementById() call reference?
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Evangelist
    Join Date
    Jul 2008
    Location
    Port Elizabeth, South Africa
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah Stephen thank you! I hadn't thought of the href problem. And I see I do have in my header a js that Paul wrote:

    var sfEls = document.getElementById("btmnav").getElementsByTagName("LI");

    thanks too for the link Ryan

  5. #5
    SitePoint Member wantmillionaire's Avatar
    Join Date
    Dec 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Seems it's more popular to use div structure nowadays. It's more convenient to control the display. I'm trying to abandon the table structure when I work on a page.


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
  •