How to use the htmlparser2.DomUtils.getElementById function in htmlparser2

To help you get started, we’ve selected a few htmlparser2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fb55 / css-select / test / qwery / index.js View on Github external
"should not get weird tokens": function() {
            expect(CSSselect('div .tokens[title="one"]', document)[0]).to.be(
                DomUtils.getElementById("token-one", document)
            ); //found div .tokens[title="one"]
            expect(CSSselect('div .tokens[title="one two"]', document)[0]).to.be(
                DomUtils.getElementById("token-two", document)
            ); //found div .tokens[title="one two"]
            expect(CSSselect('div .tokens[title="one two three #%"]', document)[0]).to.be(
                DomUtils.getElementById("token-three", document)
            ); //found div .tokens[title="one two three #%"]
            expect(CSSselect("div .tokens[title='one two three #%'] a", document)[0]).to.be(
                DomUtils.getElementById("token-four", document)
            ); //found div .tokens[title=\'one two three #%\'] a
            expect(CSSselect('div .tokens[title="one two three #%"] a[href$=foo] div', document)[0]).to.be(
                DomUtils.getElementById("token-five", document)
            ); //found div .tokens[title="one two three #%"] a[href=foo] div
        }
    },
github fb55 / css-select / test / qwery / index.js View on Github external
"get elements by attribute": function() {
            var wanted = CSSselect("#boosh div[test]", document)[0];
            var expected = DomUtils.getElementById("booshTest", document);
            expect(wanted).to.be(expected); //found attribute
            expect(CSSselect("#boosh div[test=fg]", document)[0]).to.be(expected); //found attribute with value
            expect(CSSselect('em[rel~="copyright"]', document)).to.have.length(1); //found em[rel~="copyright"]
            expect(CSSselect('em[nopass~="copyright"]', document)).to.be.empty(); //found em[nopass~="copyright"]
        },
github fb55 / css-select / test / qwery / index.js View on Github external
"[attr*=val]": function() {
            var expected = DomUtils.getElementById("attr-test-3", document);
            expect(CSSselect("#attributes div[test*=hree]", document)[0]).to.be(expected); //found attribute with *=
        },
github fb55 / css-select / test / qwery / index.js View on Github external
"<p></p>"
);

var doc = helper.getDOM(
    '<div id="hsoob">' +
        '<div class="a b">' +
        '<div id="booshTest" class="d e sib"><p><span id="spanny"></span></p></div>' +
        '<em class="sib" rel="copyright booshrs"></em>' +
        '<span class="h i a sib"></span>' +
        "</div>" +
        '<p class="odd"></p>' +
        "</div>" +
        '<div id="lonelyHsoob"></div>'
);

var el = DomUtils.getElementById("attr-child-boosh", document);

var pseudos = DomUtils.getElementById("pseudos", document).children.filter(DomUtils.isTag);

module.exports = {
    Contexts: {
        "should be able to pass optional context": function() {
            expect(CSSselect(".a", document)).to.have.length(3); //no context found 3 elements (.a)
            expect(CSSselect(".a", CSSselect("#boosh", document))).to.have.length(2); //context found 2 elements (#boosh .a)
        },

        /*
	'should be able to pass string as context': function() {
		expect(CSSselect('.a', '#boosh')).to.have.length(2); //context found 2 elements(.a, #boosh)
		expect(CSSselect('.a', '.a')).to.be.empty(); //context found 0 elements(.a, .a)
		expect(CSSselect('.a', '.b')).to.have.length(1); //context found 1 elements(.a, .b)
		expect(CSSselect('.a', '#boosh .b')).to.have.length(1); //context found 1 elements(.a, #boosh .b)
github fb55 / css-select / test / qwery / index.js View on Github external
"should not get weird tokens": function() {
            expect(CSSselect('div .tokens[title="one"]', document)[0]).to.be(
                DomUtils.getElementById("token-one", document)
            ); //found div .tokens[title="one"]
            expect(CSSselect('div .tokens[title="one two"]', document)[0]).to.be(
                DomUtils.getElementById("token-two", document)
            ); //found div .tokens[title="one two"]
            expect(CSSselect('div .tokens[title="one two three #%"]', document)[0]).to.be(
                DomUtils.getElementById("token-three", document)
            ); //found div .tokens[title="one two three #%"]
            expect(CSSselect("div .tokens[title='one two three #%'] a", document)[0]).to.be(
                DomUtils.getElementById("token-four", document)
            ); //found div .tokens[title=\'one two three #%\'] a
            expect(CSSselect('div .tokens[title="one two three #%"] a[href$=foo] div', document)[0]).to.be(
                DomUtils.getElementById("token-five", document)
            ); //found div .tokens[title="one two three #%"] a[href=foo] div
        }
    },
github fb55 / css-select / test / qwery / index.js View on Github external
"[href=#x] special case": function() {
            var expected = DomUtils.getElementById("attr-test-4", document);
            expect(CSSselect('#attributes a[href="#aname"]', document)[0]).to.be(expected); //found attribute with href=#x
        },
github fb55 / css-select / test / nwmatcher / index.js View on Github external
function getById(element) {
    if (arguments.length === 1) {
        if (typeof element === "string") {
            return DomUtils.getElementById(element, document);
        }
        return element;
    } else {
        return Array.prototype.map.call(arguments, function(elem) {
            return getById(elem);
        });
    }
}
github fb55 / css-select / test / qwery / index.js View on Github external
"[attr|=val]": function() {
            var expected = DomUtils.getElementById("attr-test-2", document);
            expect(CSSselect('#attributes div[test|="two-foo"]', document)[0]).to.be(expected); //found attribute with |=
            expect(CSSselect("#attributes div[test|=two]", document)[0]).to.be(expected); //found attribute with |=
        },
github fb55 / css-select / test / nwmatcher / scotch.js View on Github external
function getById(element) {
    if (arguments.length === 1) {
        if (typeof element === "string") {
            return DomUtils.getElementById(element, document);
        }
        return element;
    } else
        return Array.prototype.map.call(arguments, function(elem) {
            return getById(elem);
        });
}
github fb55 / css-select / test / qwery / index.js View on Github external
"should not get weird tokens": function() {
            expect(CSSselect('div .tokens[title="one"]', document)[0]).to.be(
                DomUtils.getElementById("token-one", document)
            ); //found div .tokens[title="one"]
            expect(CSSselect('div .tokens[title="one two"]', document)[0]).to.be(
                DomUtils.getElementById("token-two", document)
            ); //found div .tokens[title="one two"]
            expect(CSSselect('div .tokens[title="one two three #%"]', document)[0]).to.be(
                DomUtils.getElementById("token-three", document)
            ); //found div .tokens[title="one two three #%"]
            expect(CSSselect("div .tokens[title='one two three #%'] a", document)[0]).to.be(
                DomUtils.getElementById("token-four", document)
            ); //found div .tokens[title=\'one two three #%\'] a
            expect(CSSselect('div .tokens[title="one two three #%"] a[href$=foo] div', document)[0]).to.be(
                DomUtils.getElementById("token-five", document)
            ); //found div .tokens[title="one two three #%"] a[href=foo] div
        }
    },