>Yes, getElementById returns the first one found, i.e. the first one in the
>dom, if there are multiple nodes with the same id.

The fact that jQuery looks for the id first, then the tag definitely
improves performance, but causes the following example to fail:

<script type="text/javascript">
$(document).ready(
        function (){
                $("div#bam").append(" -- yellow");
                $("p#bam").append(" -- pink");
        }
);
</script>

<style type="text/css">
        div#bam {
                background-color: yellow;
        }

        p#bam {
                background-color: pink;
        }
</style>

<div>

        <div id="bam">I'm div#bam!</div>

        <p id="bam">I'm p#bam!</p>

</div>

If you run this example, the <div /> has a yellow background and the <p />
has a pink background. 

However, only the <div /> get it's text appended to it. You can work around
it by doing:

$("[EMAIL PROTECTED]'bam']").append(" -- pink");

This just isn't exactly intuitive and can be confusing to people who'd
expect a valid CSS selector rule to work in jQuery.

-Dan

Reply via email to