Search code examples
htmlcsspseudo-class

CSS Selector :almost-empty?


I'm aware that the :empty pseudo-class will select all elements with no children, but I want to only select elements with text-nodes as children.

I have a bottom-border on my hyperlinks that're a different color than the text, but this is a problem because the hyperlinked images are also getting this underline.

I've tried a *:not(*){ border-bottom-width: 0; } in an attempt to fix this, but it didn't work. Is there a way to select a tags with only text-nodes for children?


Solution

  • I ended up just using jQuery. I don't believe it's possible with just CSS right now.

    jQuery('document').ready(function(){
        jQuery("a").each(function(){
            if(this.children.length !== 0)
                this.style.borderBottomWidth='0';
        });
    });