diff --git a/Base/home/anon/www/dom.html b/Base/home/anon/www/dom.html index 0c6a15dfad..05fab7cbb9 100644 --- a/Base/home/anon/www/dom.html +++ b/Base/home/anon/www/dom.html @@ -4,9 +4,8 @@
diff --git a/Libraries/LibWeb/Bindings/DocumentWrapper.cpp b/Libraries/LibWeb/Bindings/DocumentWrapper.cpp index 91836d7c8e..2f0d80669a 100644 --- a/Libraries/LibWeb/Bindings/DocumentWrapper.cpp +++ b/Libraries/LibWeb/Bindings/DocumentWrapper.cpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace Web { namespace Bindings { @@ -9,6 +10,15 @@ namespace Bindings { DocumentWrapper::DocumentWrapper(Document& document) : NodeWrapper(document) { + put_native_function("getElementById", [this](JS::Interpreter&, Vector arguments) -> JS::Value { + if (arguments.is_empty()) + return JS::js_null(); + auto id = arguments[0].to_string(); + auto* element = node().get_element_by_id(id); + if (!element) + return JS::js_null(); + return wrap(heap(), const_cast(*element)); + }); } DocumentWrapper::~DocumentWrapper() diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.h index 3cf67681a3..2cb4124ebb 100644 --- a/Libraries/LibWeb/DOM/Node.h +++ b/Libraries/LibWeb/DOM/Node.h @@ -58,6 +58,8 @@ class Node : public TreeNode , public Bindings::Wrappable { public: + using WrapperType = Bindings::NodeWrapper; + virtual ~Node(); NodeType type() const { return m_type; }