Take the 2-minute tour ×

According to the specification here: http://www.w3.org/TR/CSS21/selector.html#adjacent-selectors


So how can we select the non-element sibling node. For example: in the following html, how can we select the "Non-element text" text?

<div><label>Some text here</label> Non-element text</div>
share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

You can't. CSS selectors can only select element nodes. This is why the adjacent sibling combinator works as described.

If you need to apply styles, try applying them to the div and overriding them in the label. This does depend on what styles you're applying, of course, since some of the styles can't be undone or are subject to inheritance.

share|improve this answer
Thank you. In fact, that html page is external and I cannot modify it. My main purpose is to parse that page. I am using this tool apify.heroku.com/resources/new and want to find a proper css selector for that. But if it is not do-able as you said, I will find another way. –  N. Q. P Nov 20 '12 at 9:28
add comment

As stated before, CSS selectors can only select element nodes.

To solve your problem, you can either wrap the text node in an element, and apply styles on this element, or apply the style on the container element, and override it in the label element.

share|improve this answer
add comment

Your Answer


