views:

94

answers:

2
$(this).parent().parent()
.children(this.attr("tagName").toLowerCase())
.css("background-color", "yellow");

xpath:

/html/body/div/table/tr/td/b/a

$(this).tagName is Anchor <a>

the problem with this is that children() looks at the immediate children of $(this).parent().parent(). Hence it will highlight <b> instead of <a>

i need a way to ignore this immediate children restriction, and select <a> not `

A: 

Try:

$(this).css("background-color", "yellow");

Unless you are trying to highlight all tags at the same level as "this" in which case try:

$(this).siblings("a").css("background-color", "yellow");
Daniel Worthington
+2  A: 

Use find() to search all descendants:

$(this).parent().parent()
.find(this.attr("tagName").toLowerCase())
.css("background-color", "yellow");
cletus