Here you can find the source of getElementByTag(HTMLDocument htmlDoc, int offset, Tag tag)
public static Element getElementByTag(HTMLDocument htmlDoc, int offset, Tag tag)
//package com.java2s; //License from project: LGPL import javax.swing.text.Element; import javax.swing.text.StyleConstants; import javax.swing.text.html.HTML.Tag; import javax.swing.text.html.HTMLDocument; public class Main { public static Element getElementByTag(HTMLDocument htmlDoc, int offset, Tag tag) { Element e = htmlDoc.getCharacterElement(offset); while (e != null && !e.getAttributes().containsAttribute(StyleConstants.NameAttribute, tag)) { e = e.getParentElement();//w ww.j a v a2 s . c o m } return e; } }