[webkit-dev] Identifying a div element

Pradnya Pathak pradnya.pathak at gmail.com
Tue Oct 21 04:14:40 PDT 2008


Thanks once again!

Regards,
Pradnya

On Tue, Oct 21, 2008 at 4:36 PM, Julien Chaffraix <jchaffraix at pleyo.com>wrote:

> [CC'ing the list again]
>
> On Tue, Oct 21, 2008 at 12:15 PM, Pradnya Pathak <pradnya.pathak at gmail.com
> > wrote:
>
>> Thanks Julien! It's working.
>> Is it needed to check curNode->isElement()? Or, can I directly do
>> node->hasTagName(divTag)?
>>
>
> The code has changed and so my answer was inaccurate (my bad):
>
> - if you check manually as I told you (the old method), you need to
> call curNode->isElementNode() (and not isElement()) before doing the
> static_cast as you are not sure you have an Element.
>
> - or as you were pointing out, you can use Node::hasTagName() directly. It
> will do exactly like the previous point (it is just an helper method).
>
> All in all, you should use Node::hasTagName directly.
>
> Regards,
> Julien
>
>
>> Regards,
>> Pradnya
>>
>> On Tue, Oct 21, 2008 at 3:41 PM, Julien Chaffraix <jchaffraix at pleyo.com>wrote:
>>
>>> Hi,
>>>
>>> > 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.
>>>
>>> Regards,
>>> Julien
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.webkit.org/pipermail/webkit-dev/attachments/20081021/e1c05898/attachment.html 


More information about the webkit-dev mailing list