jquery - CSS selector :contains() doesn't work with line breaks -


<div>some reallllly realllyyy long text</div> 

will render some reallllly realllyyy long text because html removes line breaks.

but can't find div using :contains() css selector because of line break:

// returns empty array $(':contains("some reallllly realllyyy long text")'); 

is there way select div , ignore line-break?

note: don't want add line break in selector, want able select div without knowing there line break (because use text user can see, , can't see line break)

what overriding :contains selector :

$.expr[":"].contains = $.expr.createpseudo(function(arg) {     return function( elem ) {         return $(elem).text().replace(/(\n)+/g, " ").indexof(arg) >= 0;     }; }); 

see fiddle

with such solution, don't have change in code add piece of code. not practice.
of course name selector other way. in case, use both of behaviours :

$.expr[":"].mycontains

see other fiddle


Comments