[webkit-dev] Identifying a div element

Julien Chaffraix jchaffraix at pleyo.com
Tue Oct 21 03:11:51 PDT 2008


> How can I check if a Node is a HTMLDivElement. I want to traverse from a
> child node upto the parent node, until I reach a div node.

You need first to check that it is an Element with the method
isElement(), then cast it as an Element and check its tag name with
Element::hasTagName() (in your case against HTMLNames::divTag). The
code will look like for your use case:

Node* curNode = ... ;

if (curNode->isElement() &&
static_cast<Element*>(curNode)->hasTagName(HTMLNames::divTag)) {
    // This is an html <div> element.

This method works for pretty much any type of element using the right tag.


More information about the webkit-dev mailing list