Where would I put the "jQuery.expr" code you created? Would love to
test.
And thanks in advance!



On Sep 3, 10:32 am, KeeganWatkins <keeganwatk...@gmail.com> wrote:
> You can always create a new selector, one that works *almost*
> as :contains does. The issue in your case (as I understand it) is
> that :contains does a global search, so text that is not at the
> beginning is still matched. It sounds like what you need is a :begins-
> with filter.
> Extending the filter engine is easy:
>
> // UNTESTED!!!
> jQuery.expr[ ":" ]["begins-with"] = function(elem, index, match) {
>     return ( new RegExp("^" + match[3]).test( elem.textContent ||
> elem.innerText || "" ));
>
> }
>
> To use, create a selector using that filter.
> $("p:begins-with('someText')'')
>
> Hope that helps.
>
> On Sep 3, 3:32 am, dashard <dash...@gmail.com> wrote:
>
> > Is there a way -- I've wracked my brains on this but I'm a jQuery
> > novice -- to determine what the first letter of a selector is?
>
> > For example, if the very first letter of a paragraph is a quote (or a
> > &lsquo; , or a &ldquo; , etc) I would like to apply a negative text-
> > indent to the found paragraph so as to replicate "hanging quotes" that
> > are commonplace in the print world.
>
> > The code I've come up with is:
>
> >         $("p:contains(“), h1:contains(“), h2:contains(“)").css({'text-
> > indent':'-0.3em'});
>
> > but this grabs any p or h1 or h2 that *contains* an opening curly
> > quote; not what I'm looking for. I need it to select paragraphs that
> > *start* with the opening curly quote.
>
> > Incidentally, I could not get this to work when I was searching for     $
> > ("p:contains(\&\#8220\;)... but it worked when I entered an actual
> > opening curly quote in the search (as above top). I tried both single
> > and double escapes too.
>
> > Any help would be greatly appreciated. I would love to roll this out
> > as a plugin, since it seems simple and really enhances the look of a
> > page of text to have the opening quotes hanging properly.

Reply via email to