3 ms·
I had no idea what ~ did after reading that post. Should have simply stated that: "The tilde (~) selector lets you target a sibling element. That is, an elemen
by latch 14y ago
I had no idea what ~ did after reading that post. Should have simply stated that:
"The tilde (~) selector lets you target a sibling element. That is, an element that shares the same parent"
Could then explain how it's different than the + selector.
"This differs from the + selector which will only find an adjacent sibling (immediately following)."
I'd consider comparing it to the child and descendant selector, if I could word it properly. This is what I have which I'm not happy with:
"In some ways, the differences between + and ~ are like the differences between the child selector (>) and the descendant selector (a space), in that #header > a will only a elements directly under #header, while header a will target all a elements under #header, regardless of depth.
- neduma 14y agoThis is far better then original article. +1
- alanh 14y ago“…sibling element. That is, an element that shares the same parent.” Unfortunately, that is not true. It only matches following siblings. See my JSFiddle demo: http://jsfiddle.net/alanhogan/sSVCG/ http://jsfiddle.net/alanhogan/sSVCG/ (Also, HTML comments between elements apparently mess up IE7 and IE8.)
- StavrosK 14y ago"+ will select the immediately following sibling, ~ will select any (one?) subsequent sibling" is plenty clear, I think?