tags:

views:

216

answers:

5

I have a:

<h2>foo<br/>bar</h2>

and I'd like to hide "bar", but I can't figure out a proper selector.

Is it even possible?

+2  A: 

There isn't a selector for it as far as I know. A possible (hacky) solution would be to set a height for the H2 element and add overflow: hidden;

ylebre
+3  A: 

Try h2:not(:first-line)

It's doubtful that this works though, first-line is rather buggy across browsers. (see http://docs.jquery.com/Selectors/not#selector and http://www.w3schools.com/Css/pr_pseudo_first-line.asp )

Wolfr
PPK has some more info about first-line as well - http://www.quirksmode.org/css/contents.html#t18
Dan F
Do you have tested? I tried this does not work. JQuery does not support: first-line
Gordian Yuan
:first-line is a CSS pseudo-class, but jQuery didn't implement it. Maybe you can try an all-css solution, that's actually a good idea if it works cross-browser.
Kobi
+11  A: 

I think you should wrap B in <span>B</span> and hide that span.

alamar
+6  A: 

First: the correct way is to add another tag, if you can, as the others suggested.
However, this can be done using jQuery's contents() selector, in two stages (I've googled on how to find text nodes with jQuery). First, on $(document).ready, find all free text nodes and surround them with dummy <span>s (or whatever you want). Given, this will spam your DOM a little:

$(document).ready(function(){
 $("h2").contents()
    .filter(function(){ return this.nodeType != 1; })
    .wrap("<span/>");
});

Now you don't have any naked text nodes, so you can easily select the second line:

$("h2 br").nextAll();
Kobi
Does this work? I votes for the idea alone :O)
Adrian Lynch
Yes, it works, at least on Firefox and IE6. and Thanks.
Kobi
+2  A: 

An all css solution:

h2 {
    font-size:0%;
}
h2:first-line {
    font-size:19pt;
}
billyswong