Pregunta

The comment in the code shows where the space is after the selector. If I remove the space before the closing quote the code breaks and I do not understand why. Can someone please explain? Thank you.

<script type="text/javascript">

    $("document").ready(function() {    
        buildBookmarks('h3', 'header'); 
    }); 

    function buildBookmarks(strWhichTag, sBookMarkNode) {

        var cAnchorCount = 0;
        var oList = $("<ul id='bookmarksList'>"); 

Below is the space after the closing )

        $("div:not([id=header]) " + strWhichTag).each(function() {
            $(this).html("<a name='bookmark" + cAnchorCount + "'></a>" + $(this).html());
            oList.append($("<li><a href='#bookmark" + cAnchorCount++  + "'>" + $(this).text() + "</a></li>"));
        });

        $("#" + sBookMarkNode).append(oList);
    }
</script>
¿Fue útil?

Solución

Apparently strWhichTag contains another selector, and it is meant to represent a child of div:not(...) when these two selector strings are concatenated.

For example, consider the difference between div.foo (div with a class name "foo") and div .foo (element with a class name "foo", which is a child of a div)

Otros consejos

According to the W3C :

A descendant selector is made up of two or more selectors separated by white space. A descendant selector of the form "A B" matches when an element B is an arbitrary descendant of some ancestor element A.

http://www.w3.org/TR/CSS2/selector.html#descendant-selectors

If strWhichTag is a child of div:not([id=header]), there must be a space between the two.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top